Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,6 @@ func NewVersionedTLSClientFromBytes(endpoint string, certPEMBlock, keyPEMBlock,
}
tr := defaultTransport()
tr.TLSClientConfig = tlsConfig
if err != nil {
return nil, err
}
c := &Client{
HTTPClient: &http.Client{Transport: tr},
TLSConfig: tlsConfig,
Expand Down Expand Up @@ -1073,7 +1070,8 @@ func parseEndpoint(endpoint string, tls bool) (*url.URL, error) {
case "http", "https", "tcp":
_, port, err := net.SplitHostPort(u.Host)
if err != nil {
if e, ok := err.(*net.AddrError); ok {
var e *net.AddrError
if errors.As(err, &e) {
if e.Err == "missing port in address" {
return u, nil
}
Expand Down
45 changes: 30 additions & 15 deletions docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ func (c *Client) inspectContainer(id string, opts doOptions) (*Container, error)
path := "/containers/" + id + "/json"
resp, err := c.do("GET", path, opts)
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: id}
}
return nil, err
Expand All @@ -579,7 +580,8 @@ func (c *Client) ContainerChanges(id string) ([]Change, error) {
path := "/containers/" + id + "/changes"
resp, err := c.do("GET", path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: id}
}
return nil, err
Expand Down Expand Up @@ -629,7 +631,8 @@ func (c *Client) CreateContainer(opts CreateContainerOptions) (*Container, error
},
)

if e, ok := err.(*Error); ok {
var e *Error
if errors.As(err, &e) {
if e.Status == http.StatusNotFound {
return nil, ErrNoSuchImage
}
Expand Down Expand Up @@ -836,7 +839,8 @@ func (c *Client) startContainer(id string, hostConfig *HostConfig, opts doOption
}
resp, err := c.do("POST", path, opts)
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id, Err: err}
}
return err
Expand Down Expand Up @@ -869,7 +873,8 @@ func (c *Client) stopContainer(id string, timeout uint, opts doOptions) error {
path := fmt.Sprintf("/containers/%s/stop?t=%d", id, timeout)
resp, err := c.do("POST", path, opts)
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
return err
Expand All @@ -889,7 +894,8 @@ func (c *Client) RestartContainer(id string, timeout uint) error {
path := fmt.Sprintf("/containers/%s/restart?t=%d", id, timeout)
resp, err := c.do("POST", path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
return err
Expand All @@ -905,7 +911,8 @@ func (c *Client) PauseContainer(id string) error {
path := fmt.Sprintf("/containers/%s/pause", id)
resp, err := c.do("POST", path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
return err
Expand All @@ -921,7 +928,8 @@ func (c *Client) UnpauseContainer(id string) error {
path := fmt.Sprintf("/containers/%s/unpause", id)
resp, err := c.do("POST", path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
return err
Expand Down Expand Up @@ -951,7 +959,8 @@ func (c *Client) TopContainer(id string, psArgs string) (TopResult, error) {
path := fmt.Sprintf("/containers/%s/top%s", id, args)
resp, err := c.do("GET", path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return result, &NoSuchContainer{ID: id}
}
return result, err
Expand Down Expand Up @@ -1131,7 +1140,8 @@ func (c *Client) Stats(opts StatsOptions) (retErr error) {
reqSent: reqSent,
})
if err != nil {
dockerError, ok := err.(*Error)
var dockerError *Error
ok := errors.As(err, &dockerError)
if ok {
if dockerError.Status == http.StatusNotFound {
err = &NoSuchContainer{ID: opts.ID}
Expand Down Expand Up @@ -1192,7 +1202,8 @@ func (c *Client) KillContainer(opts KillContainerOptions) error {
path := "/containers/" + opts.ID + "/kill" + "?" + queryString(opts)
resp, err := c.do("POST", path, doOptions{context: opts.Context})
if err != nil {
e, ok := err.(*Error)
var e *Error
ok := errors.As(err, &e)
if !ok {
return err
}
Expand Down Expand Up @@ -1233,7 +1244,8 @@ func (c *Client) RemoveContainer(opts RemoveContainerOptions) error {
path := "/containers/" + opts.ID + "?" + queryString(opts)
resp, err := c.do("DELETE", path, doOptions{context: opts.Context})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: opts.ID}
}
return err
Expand Down Expand Up @@ -1321,7 +1333,8 @@ func (c *Client) CopyFromContainer(opts CopyFromContainerOptions) error {
context: opts.Context,
})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchContainer{ID: opts.Container}
}
return err
Expand Down Expand Up @@ -1351,7 +1364,8 @@ func (c *Client) WaitContainerWithContext(id string, ctx context.Context) (int,
func (c *Client) waitContainer(id string, opts doOptions) (int, error) {
resp, err := c.do("POST", "/containers/"+id+"/wait", opts)
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return 0, &NoSuchContainer{ID: id}
}
return 0, err
Expand Down Expand Up @@ -1388,7 +1402,8 @@ func (c *Client) CommitContainer(opts CommitContainerOptions) (*Image, error) {
context: opts.Context,
})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: opts.Container}
}
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions docker/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (eventState *eventMonitoringState) monitorEvents(c *Client) {
eventState.updateLastSeen(ev)
eventState.sendEvent(ev)
case err = <-eventState.errC:
if err == ErrNoListeners {
if errors.Is(err, ErrNoListeners) {
eventState.disableEventMonitoring()
return
} else if err != nil {
Expand Down Expand Up @@ -349,7 +349,7 @@ func (c *Client) eventHijack(startTime int64, eventChan chan *APIEvents, errChan
for {
var event APIEvents
if err = decoder.Decode(&event); err != nil {
if err == io.EOF || err == io.ErrUnexpectedEOF {
if err == io.EOF || errors.Is(io.ErrUnexpectedEOF, err) {
c.eventMonitor.RLock()
if c.eventMonitor.enabled && c.eventMonitor.C == eventChan {
// Signal that we're exiting.
Expand Down
9 changes: 6 additions & 3 deletions docker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (c *Client) CreateExec(opts CreateExecOptions) (*Exec, error) {
path := fmt.Sprintf("/containers/%s/exec", opts.Container)
resp, err := c.do("POST", path, doOptions{data: opts, context: opts.Context})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: opts.Container}
}
return nil, err
Expand Down Expand Up @@ -120,7 +121,8 @@ func (c *Client) StartExecNonBlocking(id string, opts StartExecOptions) (CloseWa
if opts.Detach {
resp, err := c.do("POST", path, doOptions{data: opts, context: opts.Context})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchExec{ID: id}
}
return nil, err
Expand Down Expand Up @@ -193,7 +195,8 @@ func (c *Client) InspectExec(id string) (*ExecInspect, error) {
path := fmt.Sprintf("/exec/%s/json", id)
resp, err := c.do("GET", path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchExec{ID: id}
}
return nil, err
Expand Down
12 changes: 8 additions & 4 deletions docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ type ImageHistory struct {
func (c *Client) ImageHistory(name string) ([]ImageHistory, error) {
resp, err := c.do("GET", "/images/"+name+"/history", doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, ErrNoSuchImage
}
return nil, err
Expand All @@ -160,7 +161,8 @@ func (c *Client) ImageHistory(name string) ([]ImageHistory, error) {
func (c *Client) RemoveImage(name string) error {
resp, err := c.do("DELETE", "/images/"+name, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return ErrNoSuchImage
}
return err
Expand All @@ -187,7 +189,8 @@ func (c *Client) RemoveImageExtended(name string, opts RemoveImageOptions) error
uri := fmt.Sprintf("/images/%s?%s", name, queryString(&opts))
resp, err := c.do("DELETE", uri, doOptions{context: opts.Context})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return ErrNoSuchImage
}
return err
Expand All @@ -202,7 +205,8 @@ func (c *Client) RemoveImageExtended(name string, opts RemoveImageOptions) error
func (c *Client) InspectImage(name string) (*Image, error) {
resp, err := c.do("GET", "/images/"+name+"/json", doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, ErrNoSuchImage
}
return nil, err
Expand Down
12 changes: 8 additions & 4 deletions docker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (c *Client) NetworkInfo(id string) (*Network, error) {
path := "/networks/" + id
resp, err := c.do("GET", path, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return nil, &NoSuchNetwork{ID: id}
}
return nil, err
Expand Down Expand Up @@ -184,7 +185,8 @@ func (c *Client) CreateNetwork(opts CreateNetworkOptions) (*Network, error) {
func (c *Client) RemoveNetwork(id string) error {
resp, err := c.do("DELETE", "/networks/"+id, doOptions{})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchNetwork{ID: id}
}
return err
Expand Down Expand Up @@ -246,7 +248,8 @@ func (c *Client) ConnectNetwork(id string, opts NetworkConnectionOptions) error
context: opts.Context,
})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchNetworkOrContainer{NetworkID: id, ContainerID: opts.Container}
}
return err
Expand All @@ -262,7 +265,8 @@ func (c *Client) ConnectNetwork(id string, opts NetworkConnectionOptions) error
func (c *Client) DisconnectNetwork(id string, opts NetworkConnectionOptions) error {
resp, err := c.do("POST", "/networks/"+id+"/disconnect", doOptions{data: opts})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
var e *Error
if errors.As(err, &e) && e.Status == http.StatusNotFound {
return &NoSuchNetworkOrContainer{NetworkID: id, ContainerID: opts.Container}
}
return err
Expand Down
15 changes: 8 additions & 7 deletions docker/pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"compress/bzip2"
"compress/gzip"
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -662,25 +663,25 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
}
}

var errors []string
var errs []string
for key, value := range hdr.Xattrs {
if err := system.Lsetxattr(path, key, []byte(value), 0); err != nil {
if err == syscall.ENOTSUP {
if errors.Is(err, syscall.ENOTSUP) {
// We ignore errors here because not all graphdrivers support
// xattrs *cough* old versions of AUFS *cough*. However only
// ENOTSUP should be emitted in that case, otherwise we still
// bail.
errors = append(errors, err.Error())
errs = append(errs, err.Error())
continue
}
return err
}

}

if len(errors) > 0 {
if len(errs) > 0 {
logrus.WithFields(logrus.Fields{
"errors": errors,
"errors": errs,
}).Warn("ignored xattrs in archive: underlying filesystem doesn't support them")
}

Expand Down Expand Up @@ -709,7 +710,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
}
} else {
ts := []syscall.Timespec{timeToTimespec(aTime), timeToTimespec(hdr.ModTime)}
if err := system.LUtimesNano(path, ts); err != nil && err != system.ErrNotSupportedPlatform {
if err := system.LUtimesNano(path, ts); err != nil && !errors.Is(err, system.ErrNotSupportedPlatform) {
return err
}
}
Expand Down Expand Up @@ -885,7 +886,7 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
if err := ta.addTarFile(filePath, relFilePath); err != nil {
logrus.Errorf("Can't add file %s to tar: %s", filePath, err)
// if pipe is broken, stop writing tar stream to it
if err == io.ErrClosedPipe {
if errors.Is(err, io.ErrClosedPipe) {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion docker/pkg/ioutils/bytespipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ loop0:
bp.bufLen += n

// errBufferFull is an error we expect to get if the buffer is full
if err != nil && err != errBufferFull {
if err != nil && !errors.Is(err, errBufferFull) {
bp.wait.Broadcast()
bp.mu.Unlock()
return written, err
Expand Down
3 changes: 2 additions & 1 deletion docker/pkg/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package mount // import "github.com/ory/dockertest/v3/docker/pkg/mount"

import (
"errors"
"sort"
"strings"

Expand Down Expand Up @@ -93,7 +94,7 @@ func RecursiveUnmount(target string) error {
// We've purposefully used `syscall.EINVAL` here instead of `unix.EINVAL` to avoid platform branching
// Since `EINVAL` is defined for both Windows and Linux in the `syscall` package (and other platforms),
// this is nicer than defining a custom value that we can refer to in each platform file.
if err == syscall.EINVAL {
if errors.Is(err, syscall.EINVAL) {
continue
}
if i == len(mounts)-1 {
Expand Down
4 changes: 3 additions & 1 deletion docker/pkg/system/exitcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package system // import "github.com/ory/dockertest/v3/docker/pkg/system"

import (
"errors"
"fmt"
"os/exec"
"syscall"
Expand All @@ -13,7 +14,8 @@ import (
// exec.ExitError, returns 0 and an error otherwise.
func GetExitCode(err error) (int, error) {
exitCode := 0
if exiterr, ok := err.(*exec.ExitError); ok {
var exiterr *exec.ExitError
if errors.As(err, &exiterr) {
if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok {
return procExit.ExitStatus(), nil
}
Expand Down
Loading
Loading