1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

vendor: gotest.tools/v3 v3.1.0

full diff: https://github.com/gotestyourself/gotest.tools/compare/v3.0.3...v3.1.0

noteworthy changes:

- ci: add go1.16
- ci: add go1.17, remove go1.13
- golden: only create dir if update flag is set
- icmd: replace all usages of os/exec with golang.org/x/sys/execabs
- assert: ErrorIs
- fs: add DirFromPath
- Stop creating directory outside of testdata
- fs: Fix comparing symlink permissions

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-03-01 17:02:53 +01:00
parent c35143f92e
commit 89d39e5e77
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
10 changed files with 101 additions and 17 deletions

View file

@ -0,0 +1,20 @@
// +build go1.13
package assert
import (
"gotest.tools/v3/assert/cmp"
"gotest.tools/v3/internal/assert"
)
// ErrorIs fails the test if err is nil, or the error does not match expected
// when compared using errors.Is. See https://golang.org/pkg/errors/#Is for
// accepted argument values.
func ErrorIs(t TestingT, err error, expected error, msgAndArgs ...interface{}) {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
if !assert.Eval(t, assert.ArgsAfterT, cmp.ErrorIs(err, expected), msgAndArgs...) {
t.FailNow()
}
}

View file

@ -0,0 +1,29 @@
// +build go1.13
package cmp
import (
"errors"
)
// ErrorIs succeeds if errors.Is(actual, expected) returns true. See
// https://golang.org/pkg/errors/#Is for accepted argument values.
func ErrorIs(actual error, expected error) Comparison {
return func() Result {
if errors.Is(actual, expected) {
return ResultSuccess
}
return ResultFailureTemplate(`error is
{{- if not .Data.a }} nil,{{ else }}
{{- printf " \"%v\"" .Data.a}} (
{{- with callArg 0 }}{{ formatNode . }} {{end -}}
{{- printf "%T" .Data.a -}}
),
{{- end }} not {{ printf "\"%v\"" .Data.x}} (
{{- with callArg 1 }}{{ formatNode . }} {{end -}}
{{- printf "%T" .Data.x -}}
)`,
map[string]interface{}{"a": actual, "x": expected})
}
}

View file

@ -113,3 +113,19 @@ func (d *Dir) Remove() {
func (d *Dir) Join(parts ...string) string {
return filepath.Join(append([]string{d.Path()}, parts...)...)
}
// DirFromPath returns a Dir for a path that already exists. No directory is created.
// Unlike NewDir the directory will not be removed automatically when the test exits,
// it is the callers responsibly to remove the directory.
// DirFromPath can be used with Apply to modify an existing directory.
//
// If the path does not already exist, use NewDir instead.
func DirFromPath(t assert.TestingT, path string, ops ...PathOp) *Dir {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
dir := &Dir{path: path}
assert.NilError(t, applyPathOps(dir, ops))
return dir
}

View file

@ -1,16 +1,24 @@
//go:build !windows
// +build !windows
package fs
import (
"os"
"runtime"
"syscall"
)
const (
defaultRootDirMode = os.ModeDir | 0700
defaultSymlinkMode = os.ModeSymlink | 0777
)
const defaultRootDirMode = os.ModeDir | 0700
var defaultSymlinkMode = os.ModeSymlink | 0777
func init() {
switch runtime.GOOS {
case "darwin":
defaultSymlinkMode = os.ModeSymlink | 0755
}
}
func newResourceFromInfo(info os.FileInfo) resource {
statT := info.Sys().(*syscall.Stat_t)

View file

@ -7,11 +7,11 @@ import (
"fmt"
"io"
"os"
"os/exec"
"strings"
"sync"
"time"
exec "golang.org/x/sys/execabs"
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
)

View file

@ -1,10 +1,10 @@
package icmd
import (
"os/exec"
"syscall"
"github.com/pkg/errors"
exec "golang.org/x/sys/execabs"
)
// getExitCode returns the ExitStatus of a process from the error returned by

View file

@ -11,16 +11,20 @@ type Check func(t LogT) Result
// FileExists looks on filesystem and check that path exists.
func FileExists(path string) Check {
return func(t LogT) Result {
_, err := os.Stat(path)
if os.IsNotExist(err) {
t.Logf("waiting on file %s to exist", path)
return Continue("file %s does not exist", path)
}
if err != nil {
return Error(err)
if h, ok := t.(helperT); ok {
h.Helper()
}
return Success()
_, err := os.Stat(path)
switch {
case os.IsNotExist(err):
t.Logf("waiting on file %s to exist", path)
return Continue("file %s does not exist", path)
case err != nil:
return Error(err)
default:
return Success()
}
}
}
@ -29,6 +33,10 @@ func FileExists(path string) Check {
// address parameters.
func Connection(network, address string) Check {
return func(t LogT) Result {
if h, ok := t.(helperT); ok {
h.Helper()
}
_, err := net.Dial(network, address)
if err != nil {
t.Logf("waiting on socket %s://%s to be available...", network, address)