mirror of https://github.com/docker/cli.git
vendor: gotest.tools/v3 v3.5.0
- go.mod: update dependencies and go version by
- Use Go1.20
- Fix couple of typos
- Added `WithStdout` and `WithStderr` helpers
- Moved `cmdOperators` handling from `RunCmd` to `StartCmd`
- Deprecate `assert.ErrorType`
- Remove outdated Dockerfile
- add godoc links
full diff: https://github.com/gotestyourself/gotest.tools/compare/v3.4.0...v3.5.0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 0b535c791a
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
67df4e8ca7
commit
4a1dd71c8c
|
@ -117,7 +117,10 @@ issues:
|
||||||
- text: "package-comments: should have a package comment"
|
- text: "package-comments: should have a package comment"
|
||||||
linters:
|
linters:
|
||||||
- revive
|
- revive
|
||||||
|
# FIXME temporarily suppress these (see https://github.com/gotestyourself/gotest.tools/issues/272)
|
||||||
|
- text: "SA1019: (assert|cmp|is)\\.ErrorType is deprecated"
|
||||||
|
linters:
|
||||||
|
- staticcheck
|
||||||
# Exclude some linters from running on tests files.
|
# Exclude some linters from running on tests files.
|
||||||
- path: _test\.go
|
- path: _test\.go
|
||||||
linters:
|
linters:
|
||||||
|
|
|
@ -42,7 +42,7 @@ require (
|
||||||
golang.org/x/term v0.6.0
|
golang.org/x/term v0.6.0
|
||||||
golang.org/x/text v0.8.0
|
golang.org/x/text v0.8.0
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
gotest.tools/v3 v3.4.0
|
gotest.tools/v3 v3.5.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|
|
@ -619,7 +619,6 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
|
||||||
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||||
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
@ -740,8 +739,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
|
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
|
||||||
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
|
gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
|
|
@ -4,7 +4,7 @@ values in tests. When an assertion fails a helpful error message is printed.
|
||||||
|
|
||||||
# Example usage
|
# Example usage
|
||||||
|
|
||||||
All the assertions in this package use testing.T.Helper to mark themselves as
|
All the assertions in this package use [testing.T.Helper] to mark themselves as
|
||||||
test helpers. This allows the testing package to print the filename and line
|
test helpers. This allows the testing package to print the filename and line
|
||||||
number of the file function that failed.
|
number of the file function that failed.
|
||||||
|
|
||||||
|
@ -67,19 +67,19 @@ message is omitted from these examples for brevity.
|
||||||
|
|
||||||
# Assert and Check
|
# Assert and Check
|
||||||
|
|
||||||
Assert and Check are very similar, they both accept a Comparison, and fail
|
[Assert] and [Check] are very similar, they both accept a [cmp.Comparison], and fail
|
||||||
the test when the comparison fails. The one difference is that Assert uses
|
the test when the comparison fails. The one difference is that Assert uses
|
||||||
testing.T.FailNow to fail the test, which will end the test execution immediately.
|
[testing.T.FailNow] to fail the test, which will end the test execution immediately.
|
||||||
Check uses testing.T.Fail to fail the test, which allows it to return the
|
Check uses [testing.T.Fail] to fail the test, which allows it to return the
|
||||||
result of the comparison, then proceed with the rest of the test case.
|
result of the comparison, then proceed with the rest of the test case.
|
||||||
|
|
||||||
Like testing.T.FailNow, Assert must be called from the goroutine running the test,
|
Like [testing.T.FailNow], [Assert] must be called from the goroutine running the test,
|
||||||
not from other goroutines created during the test. Check is safe to use from any
|
not from other goroutines created during the test. [Check] is safe to use from any
|
||||||
goroutine.
|
goroutine.
|
||||||
|
|
||||||
# Comparisons
|
# Comparisons
|
||||||
|
|
||||||
Package http://pkg.go.dev/gotest.tools/v3/assert/cmp provides
|
Package [gotest.tools/v3/assert/cmp] provides
|
||||||
many common comparisons. Additional comparisons can be written to compare
|
many common comparisons. Additional comparisons can be written to compare
|
||||||
values in other ways. See the example Assert (CustomComparison).
|
values in other ways. See the example Assert (CustomComparison).
|
||||||
|
|
||||||
|
@ -98,11 +98,11 @@ import (
|
||||||
"gotest.tools/v3/internal/assert"
|
"gotest.tools/v3/internal/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BoolOrComparison can be a bool, cmp.Comparison, or error. See Assert for
|
// BoolOrComparison can be a bool, [cmp.Comparison], or error. See [Assert] for
|
||||||
// details about how this type is used.
|
// details about how this type is used.
|
||||||
type BoolOrComparison interface{}
|
type BoolOrComparison interface{}
|
||||||
|
|
||||||
// TestingT is the subset of testing.T used by the assert package.
|
// TestingT is the subset of [testing.T] (see also [testing.TB]) used by the assert package.
|
||||||
type TestingT interface {
|
type TestingT interface {
|
||||||
FailNow()
|
FailNow()
|
||||||
Fail()
|
Fail()
|
||||||
|
@ -133,11 +133,11 @@ type helperT interface {
|
||||||
//
|
//
|
||||||
// Extra details can be added to the failure message using msgAndArgs. msgAndArgs
|
// Extra details can be added to the failure message using msgAndArgs. msgAndArgs
|
||||||
// may be either a single string, or a format string and args that will be
|
// may be either a single string, or a format string and args that will be
|
||||||
// passed to fmt.Sprintf.
|
// passed to [fmt.Sprintf].
|
||||||
//
|
//
|
||||||
// Assert uses t.FailNow to fail the test. Like t.FailNow, Assert must be called
|
// Assert uses [testing.TB.FailNow] to fail the test. Like t.FailNow, Assert must be called
|
||||||
// from the goroutine running the test function, not from other
|
// from the goroutine running the test function, not from other
|
||||||
// goroutines created during the test. Use Check from other goroutines.
|
// goroutines created during the test. Use [Check] from other goroutines.
|
||||||
func Assert(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) {
|
func Assert(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
|
@ -151,7 +151,7 @@ func Assert(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{})
|
||||||
// failed, a failure message is printed, and Check returns false. If the comparison
|
// failed, a failure message is printed, and Check returns false. If the comparison
|
||||||
// is successful Check returns true. Check may be called from any goroutine.
|
// is successful Check returns true. Check may be called from any goroutine.
|
||||||
//
|
//
|
||||||
// See Assert for details about the comparison arg and failure messages.
|
// See [Assert] for details about the comparison arg and failure messages.
|
||||||
func Check(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) bool {
|
func Check(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) bool {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
|
@ -166,9 +166,9 @@ func Check(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) b
|
||||||
// NilError fails the test immediately if err is not nil, and includes err.Error
|
// NilError fails the test immediately if err is not nil, and includes err.Error
|
||||||
// in the failure message.
|
// in the failure message.
|
||||||
//
|
//
|
||||||
// NilError uses t.FailNow to fail the test. Like t.FailNow, NilError must be
|
// NilError uses [testing.TB.FailNow] to fail the test. Like t.FailNow, NilError must be
|
||||||
// called from the goroutine running the test function, not from other
|
// called from the goroutine running the test function, not from other
|
||||||
// goroutines created during the test. Use Check from other goroutines.
|
// goroutines created during the test. Use [Check] from other goroutines.
|
||||||
func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
|
func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
|
@ -193,9 +193,9 @@ func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
|
||||||
// the unified diff will be augmented by replacing whitespace characters with
|
// the unified diff will be augmented by replacing whitespace characters with
|
||||||
// visible characters to identify the whitespace difference.
|
// visible characters to identify the whitespace difference.
|
||||||
//
|
//
|
||||||
// Equal uses t.FailNow to fail the test. Like t.FailNow, Equal must be
|
// Equal uses [testing.T.FailNow] to fail the test. Like t.FailNow, Equal must be
|
||||||
// called from the goroutine running the test function, not from other
|
// called from the goroutine running the test function, not from other
|
||||||
// goroutines created during the test. Use Check with cmp.Equal from other
|
// goroutines created during the test. Use [Check] with [cmp.Equal] from other
|
||||||
// goroutines.
|
// goroutines.
|
||||||
func Equal(t TestingT, x, y interface{}, msgAndArgs ...interface{}) {
|
func Equal(t TestingT, x, y interface{}, msgAndArgs ...interface{}) {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
|
@ -206,15 +206,15 @@ func Equal(t TestingT, x, y interface{}, msgAndArgs ...interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepEqual uses google/go-cmp (https://godoc.org/github.com/google/go-cmp/cmp)
|
// DeepEqual uses [github.com/google/go-cmp/cmp]
|
||||||
// to assert two values are equal and fails the test if they are not equal.
|
// to assert two values are equal and fails the test if they are not equal.
|
||||||
//
|
//
|
||||||
// Package http://pkg.go.dev/gotest.tools/v3/assert/opt provides some additional
|
// Package [gotest.tools/v3/assert/opt] provides some additional
|
||||||
// commonly used Options.
|
// commonly used Options.
|
||||||
//
|
//
|
||||||
// DeepEqual uses t.FailNow to fail the test. Like t.FailNow, DeepEqual must be
|
// DeepEqual uses [testing.T.FailNow] to fail the test. Like t.FailNow, DeepEqual must be
|
||||||
// called from the goroutine running the test function, not from other
|
// called from the goroutine running the test function, not from other
|
||||||
// goroutines created during the test. Use Check with cmp.DeepEqual from other
|
// goroutines created during the test. Use [Check] with [cmp.DeepEqual] from other
|
||||||
// goroutines.
|
// goroutines.
|
||||||
func DeepEqual(t TestingT, x, y interface{}, opts ...gocmp.Option) {
|
func DeepEqual(t TestingT, x, y interface{}, opts ...gocmp.Option) {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
|
@ -227,13 +227,13 @@ func DeepEqual(t TestingT, x, y interface{}, opts ...gocmp.Option) {
|
||||||
|
|
||||||
// Error fails the test if err is nil, or if err.Error is not equal to expected.
|
// Error fails the test if err is nil, or if err.Error is not equal to expected.
|
||||||
// Both err.Error and expected will be included in the failure message.
|
// Both err.Error and expected will be included in the failure message.
|
||||||
// Error performs an exact match of the error text. Use ErrorContains if only
|
// Error performs an exact match of the error text. Use [ErrorContains] if only
|
||||||
// part of the error message is relevant. Use ErrorType or ErrorIs to compare
|
// part of the error message is relevant. Use [ErrorType] or [ErrorIs] to compare
|
||||||
// errors by type.
|
// errors by type.
|
||||||
//
|
//
|
||||||
// Error uses t.FailNow to fail the test. Like t.FailNow, Error must be
|
// Error uses [testing.T.FailNow] to fail the test. Like t.FailNow, Error must be
|
||||||
// called from the goroutine running the test function, not from other
|
// called from the goroutine running the test function, not from other
|
||||||
// goroutines created during the test. Use Check with cmp.Error from other
|
// goroutines created during the test. Use [Check] with [cmp.Error] from other
|
||||||
// goroutines.
|
// goroutines.
|
||||||
func Error(t TestingT, err error, expected string, msgAndArgs ...interface{}) {
|
func Error(t TestingT, err error, expected string, msgAndArgs ...interface{}) {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
|
@ -248,9 +248,9 @@ func Error(t TestingT, err error, expected string, msgAndArgs ...interface{}) {
|
||||||
// contain the expected substring. Both err.Error and the expected substring
|
// contain the expected substring. Both err.Error and the expected substring
|
||||||
// will be included in the failure message.
|
// will be included in the failure message.
|
||||||
//
|
//
|
||||||
// ErrorContains uses t.FailNow to fail the test. Like t.FailNow, ErrorContains
|
// ErrorContains uses [testing.T.FailNow] to fail the test. Like t.FailNow, ErrorContains
|
||||||
// must be called from the goroutine running the test function, not from other
|
// must be called from the goroutine running the test function, not from other
|
||||||
// goroutines created during the test. Use Check with cmp.ErrorContains from other
|
// goroutines created during the test. Use [Check] with [cmp.ErrorContains] from other
|
||||||
// goroutines.
|
// goroutines.
|
||||||
func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interface{}) {
|
func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interface{}) {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
|
@ -262,8 +262,7 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrorType fails the test if err is nil, or err is not the expected type.
|
// ErrorType fails the test if err is nil, or err is not the expected type.
|
||||||
// Most new code should use ErrorIs instead. ErrorType may be deprecated in the
|
// New code should use ErrorIs instead.
|
||||||
// future.
|
|
||||||
//
|
//
|
||||||
// Expected can be one of:
|
// Expected can be one of:
|
||||||
//
|
//
|
||||||
|
@ -281,10 +280,12 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
|
||||||
// reflect.Type
|
// reflect.Type
|
||||||
// The assertion fails if err does not implement the reflect.Type.
|
// The assertion fails if err does not implement the reflect.Type.
|
||||||
//
|
//
|
||||||
// ErrorType uses t.FailNow to fail the test. Like t.FailNow, ErrorType
|
// ErrorType uses [testing.T.FailNow] to fail the test. Like t.FailNow, ErrorType
|
||||||
// must be called from the goroutine running the test function, not from other
|
// must be called from the goroutine running the test function, not from other
|
||||||
// goroutines created during the test. Use Check with cmp.ErrorType from other
|
// goroutines created during the test. Use [Check] with [cmp.ErrorType] from other
|
||||||
// goroutines.
|
// goroutines.
|
||||||
|
//
|
||||||
|
// Deprecated: Use [ErrorIs]
|
||||||
func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interface{}) {
|
func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interface{}) {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
|
@ -295,12 +296,12 @@ func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interf
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrorIs fails the test if err is nil, or the error does not match expected
|
// 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
|
// when compared using errors.Is. See [errors.Is] for
|
||||||
// accepted arguments.
|
// accepted arguments.
|
||||||
//
|
//
|
||||||
// ErrorIs uses t.FailNow to fail the test. Like t.FailNow, ErrorIs
|
// ErrorIs uses [testing.T.FailNow] to fail the test. Like t.FailNow, ErrorIs
|
||||||
// must be called from the goroutine running the test function, not from other
|
// must be called from the goroutine running the test function, not from other
|
||||||
// goroutines created during the test. Use Check with cmp.ErrorIs from other
|
// goroutines created during the test. Use [Check] with [cmp.ErrorIs] from other
|
||||||
// goroutines.
|
// goroutines.
|
||||||
func ErrorIs(t TestingT, err error, expected error, msgAndArgs ...interface{}) {
|
func ErrorIs(t TestingT, err error, expected error, msgAndArgs ...interface{}) {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
|
|
|
@ -12,17 +12,16 @@ import (
|
||||||
"gotest.tools/v3/internal/format"
|
"gotest.tools/v3/internal/format"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Comparison is a function which compares values and returns ResultSuccess if
|
// Comparison is a function which compares values and returns [ResultSuccess] if
|
||||||
// the actual value matches the expected value. If the values do not match the
|
// the actual value matches the expected value. If the values do not match the
|
||||||
// Result will contain a message about why it failed.
|
// [Result] will contain a message about why it failed.
|
||||||
type Comparison func() Result
|
type Comparison func() Result
|
||||||
|
|
||||||
// DeepEqual compares two values using google/go-cmp
|
// DeepEqual compares two values using [github.com/google/go-cmp/cmp]
|
||||||
// (https://godoc.org/github.com/google/go-cmp/cmp)
|
|
||||||
// and succeeds if the values are equal.
|
// and succeeds if the values are equal.
|
||||||
//
|
//
|
||||||
// The comparison can be customized using comparison Options.
|
// The comparison can be customized using comparison Options.
|
||||||
// Package http://pkg.go.dev/gotest.tools/v3/assert/opt provides some additional
|
// Package [gotest.tools/v3/assert/opt] provides some additional
|
||||||
// commonly used Options.
|
// commonly used Options.
|
||||||
func DeepEqual(x, y interface{}, opts ...cmp.Option) Comparison {
|
func DeepEqual(x, y interface{}, opts ...cmp.Option) Comparison {
|
||||||
return func() (result Result) {
|
return func() (result Result) {
|
||||||
|
@ -61,7 +60,7 @@ func toResult(success bool, msg string) Result {
|
||||||
return ResultFailure(msg)
|
return ResultFailure(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegexOrPattern may be either a *regexp.Regexp or a string that is a valid
|
// RegexOrPattern may be either a [*regexp.Regexp] or a string that is a valid
|
||||||
// regexp pattern.
|
// regexp pattern.
|
||||||
type RegexOrPattern interface{}
|
type RegexOrPattern interface{}
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ func Regexp(re RegexOrPattern, v string) Comparison {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal succeeds if x == y. See assert.Equal for full documentation.
|
// Equal succeeds if x == y. See [gotest.tools/v3/assert.Equal] for full documentation.
|
||||||
func Equal(x, y interface{}) Comparison {
|
func Equal(x, y interface{}) Comparison {
|
||||||
return func() Result {
|
return func() Result {
|
||||||
switch {
|
switch {
|
||||||
|
@ -159,10 +158,10 @@ func Len(seq interface{}, expected int) Comparison {
|
||||||
// slice, or array.
|
// slice, or array.
|
||||||
//
|
//
|
||||||
// If collection is a string, item must also be a string, and is compared using
|
// If collection is a string, item must also be a string, and is compared using
|
||||||
// strings.Contains().
|
// [strings.Contains].
|
||||||
// If collection is a Map, contains will succeed if item is a key in the map.
|
// If collection is a Map, contains will succeed if item is a key in the map.
|
||||||
// If collection is a slice or array, item is compared to each item in the
|
// If collection is a slice or array, item is compared to each item in the
|
||||||
// sequence using reflect.DeepEqual().
|
// sequence using [reflect.DeepEqual].
|
||||||
func Contains(collection interface{}, item interface{}) Comparison {
|
func Contains(collection interface{}, item interface{}) Comparison {
|
||||||
return func() Result {
|
return func() Result {
|
||||||
colValue := reflect.ValueOf(collection)
|
colValue := reflect.ValueOf(collection)
|
||||||
|
@ -259,7 +258,7 @@ func formatErrorMessage(err error) string {
|
||||||
|
|
||||||
// Nil succeeds if obj is a nil interface, pointer, or function.
|
// Nil succeeds if obj is a nil interface, pointer, or function.
|
||||||
//
|
//
|
||||||
// Use NilError() for comparing errors. Use Len(obj, 0) for comparing slices,
|
// Use [gotest.tools/v3/assert.NilError] for comparing errors. Use Len(obj, 0) for comparing slices,
|
||||||
// maps, and channels.
|
// maps, and channels.
|
||||||
func Nil(obj interface{}) Comparison {
|
func Nil(obj interface{}) Comparison {
|
||||||
msgFunc := func(value reflect.Value) string {
|
msgFunc := func(value reflect.Value) string {
|
||||||
|
@ -306,7 +305,9 @@ func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison {
|
||||||
//
|
//
|
||||||
// reflect.Type
|
// reflect.Type
|
||||||
//
|
//
|
||||||
// Fails if err does not implement the reflect.Type
|
// Fails if err does not implement the [reflect.Type].
|
||||||
|
//
|
||||||
|
// Deprecated: Use [ErrorIs]
|
||||||
func ErrorType(err error, expected interface{}) Comparison {
|
func ErrorType(err error, expected interface{}) Comparison {
|
||||||
return func() Result {
|
return func() Result {
|
||||||
switch expectedType := expected.(type) {
|
switch expectedType := expected.(type) {
|
||||||
|
@ -381,7 +382,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrorIs succeeds if errors.Is(actual, expected) returns true. See
|
// ErrorIs succeeds if errors.Is(actual, expected) returns true. See
|
||||||
// https://golang.org/pkg/errors/#Is for accepted argument values.
|
// [errors.Is] for accepted argument values.
|
||||||
func ErrorIs(actual error, expected error) Comparison {
|
func ErrorIs(actual error, expected error) Comparison {
|
||||||
return func() Result {
|
return func() Result {
|
||||||
if errors.Is(actual, expected) {
|
if errors.Is(actual, expected) {
|
||||||
|
|
|
@ -10,12 +10,12 @@ import (
|
||||||
"gotest.tools/v3/internal/source"
|
"gotest.tools/v3/internal/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Result of a Comparison.
|
// A Result of a [Comparison].
|
||||||
type Result interface {
|
type Result interface {
|
||||||
Success() bool
|
Success() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringResult is an implementation of Result that reports the error message
|
// StringResult is an implementation of [Result] that reports the error message
|
||||||
// string verbatim and does not provide any templating or formatting of the
|
// string verbatim and does not provide any templating or formatting of the
|
||||||
// message.
|
// message.
|
||||||
type StringResult struct {
|
type StringResult struct {
|
||||||
|
@ -34,16 +34,16 @@ func (r StringResult) FailureMessage() string {
|
||||||
return r.message
|
return r.message
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResultSuccess is a constant which is returned by a ComparisonWithResult to
|
// ResultSuccess is a constant which is returned by a [Comparison] to
|
||||||
// indicate success.
|
// indicate success.
|
||||||
var ResultSuccess = StringResult{success: true}
|
var ResultSuccess = StringResult{success: true}
|
||||||
|
|
||||||
// ResultFailure returns a failed Result with a failure message.
|
// ResultFailure returns a failed [Result] with a failure message.
|
||||||
func ResultFailure(message string) StringResult {
|
func ResultFailure(message string) StringResult {
|
||||||
return StringResult{message: message}
|
return StringResult{message: message}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResultFromError returns ResultSuccess if err is nil. Otherwise ResultFailure
|
// ResultFromError returns [ResultSuccess] if err is nil. Otherwise [ResultFailure]
|
||||||
// is returned with the error message as the failure message.
|
// is returned with the error message as the failure message.
|
||||||
func ResultFromError(err error) Result {
|
func ResultFromError(err error) Result {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -74,7 +74,7 @@ func (r templatedResult) UpdatedExpected(stackIndex int) error {
|
||||||
return source.UpdateExpectedValue(stackIndex+1, r.data["x"], r.data["y"])
|
return source.UpdateExpectedValue(stackIndex+1, r.data["x"], r.data["y"])
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResultFailureTemplate returns a Result with a template string and data which
|
// ResultFailureTemplate returns a [Result] with a template string and data which
|
||||||
// can be used to format a failure message. The template may access data from .Data,
|
// can be used to format a failure message. The template may access data from .Data,
|
||||||
// the comparison args with the callArg function, and the formatNode function may
|
// the comparison args with the callArg function, and the formatNode function may
|
||||||
// be used to format the call args.
|
// be used to format the call args.
|
||||||
|
|
|
@ -72,7 +72,7 @@ func PatchAll(t assert.TestingT, env map[string]string) func() {
|
||||||
return clean
|
return clean
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToMap takes a list of strings in the format returned by os.Environ() and
|
// ToMap takes a list of strings in the format returned by [os.Environ] and
|
||||||
// returns a mapping of keys to values.
|
// returns a mapping of keys to values.
|
||||||
func ToMap(env []string) map[string]string {
|
func ToMap(env []string) map[string]string {
|
||||||
result := map[string]string{}
|
result := map[string]string{}
|
||||||
|
|
|
@ -195,6 +195,7 @@ type Cmd struct {
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
Stdin io.Reader
|
Stdin io.Reader
|
||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
|
Stderr io.Writer
|
||||||
Dir string
|
Dir string
|
||||||
Env []string
|
Env []string
|
||||||
ExtraFiles []*os.File
|
ExtraFiles []*os.File
|
||||||
|
@ -207,10 +208,7 @@ func Command(command string, args ...string) Cmd {
|
||||||
|
|
||||||
// RunCmd runs a command and returns a Result
|
// RunCmd runs a command and returns a Result
|
||||||
func RunCmd(cmd Cmd, cmdOperators ...CmdOp) *Result {
|
func RunCmd(cmd Cmd, cmdOperators ...CmdOp) *Result {
|
||||||
for _, op := range cmdOperators {
|
result := StartCmd(cmd, cmdOperators...)
|
||||||
op(&cmd)
|
|
||||||
}
|
|
||||||
result := StartCmd(cmd)
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -223,7 +221,10 @@ func RunCommand(command string, args ...string) *Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartCmd starts a command, but doesn't wait for it to finish
|
// StartCmd starts a command, but doesn't wait for it to finish
|
||||||
func StartCmd(cmd Cmd) *Result {
|
func StartCmd(cmd Cmd, cmdOperators ...CmdOp) *Result {
|
||||||
|
for _, op := range cmdOperators {
|
||||||
|
op(&cmd)
|
||||||
|
}
|
||||||
result := buildCmd(cmd)
|
result := buildCmd(cmd)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result
|
return result
|
||||||
|
@ -252,7 +253,11 @@ func buildCmd(cmd Cmd) *Result {
|
||||||
} else {
|
} else {
|
||||||
execCmd.Stdout = outBuffer
|
execCmd.Stdout = outBuffer
|
||||||
}
|
}
|
||||||
|
if cmd.Stderr != nil {
|
||||||
|
execCmd.Stderr = io.MultiWriter(errBuffer, cmd.Stderr)
|
||||||
|
} else {
|
||||||
execCmd.Stderr = errBuffer
|
execCmd.Stderr = errBuffer
|
||||||
|
}
|
||||||
execCmd.ExtraFiles = cmd.ExtraFiles
|
execCmd.ExtraFiles = cmd.ExtraFiles
|
||||||
|
|
||||||
return &Result{
|
return &Result{
|
||||||
|
|
|
@ -38,6 +38,20 @@ func WithStdin(r io.Reader) CmdOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithStdout sets the standard output of the command to the specified writer
|
||||||
|
func WithStdout(w io.Writer) CmdOp {
|
||||||
|
return func(c *Cmd) {
|
||||||
|
c.Stdout = w
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithStderr sets the standard error of the command to the specified writer
|
||||||
|
func WithStderr(w io.Writer) CmdOp {
|
||||||
|
return func(c *Cmd) {
|
||||||
|
c.Stderr = w
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithExtraFile adds a file descriptor to the command
|
// WithExtraFile adds a file descriptor to the command
|
||||||
func WithExtraFile(f *os.File) CmdOp {
|
func WithExtraFile(f *os.File) CmdOp {
|
||||||
return func(c *Cmd) {
|
return func(c *Cmd) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check is a function which will be used as check for the WaitOn method.
|
// Check is a function which will be used as check for the [WaitOn] method.
|
||||||
type Check func(t LogT) Result
|
type Check func(t LogT) Result
|
||||||
|
|
||||||
// FileExists looks on filesystem and check that path exists.
|
// FileExists looks on filesystem and check that path exists.
|
||||||
|
@ -29,7 +29,7 @@ func FileExists(path string) Check {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connection try to open a connection to the address on the
|
// Connection try to open a connection to the address on the
|
||||||
// named network. See net.Dial for a description of the network and
|
// named network. See [net.Dial] for a description of the network and
|
||||||
// address parameters.
|
// address parameters.
|
||||||
func Connection(network, address string) Check {
|
func Connection(network, address string) Check {
|
||||||
return func(t LogT) Result {
|
return func(t LogT) Result {
|
||||||
|
|
|
@ -11,13 +11,13 @@ import (
|
||||||
"gotest.tools/v3/internal/assert"
|
"gotest.tools/v3/internal/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestingT is the subset of testing.T used by WaitOn
|
// TestingT is the subset of [testing.T] used by [WaitOn]
|
||||||
type TestingT interface {
|
type TestingT interface {
|
||||||
LogT
|
LogT
|
||||||
Fatalf(format string, args ...interface{})
|
Fatalf(format string, args ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogT is a logging interface that is passed to the WaitOn check function
|
// LogT is a logging interface that is passed to the [WaitOn] check function
|
||||||
type LogT interface {
|
type LogT interface {
|
||||||
Log(args ...interface{})
|
Log(args ...interface{})
|
||||||
Logf(format string, args ...interface{})
|
Logf(format string, args ...interface{})
|
||||||
|
@ -27,7 +27,7 @@ type helperT interface {
|
||||||
Helper()
|
Helper()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Settings are used to configure the behaviour of WaitOn
|
// Settings are used to configure the behaviour of [WaitOn]
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
// Timeout is the maximum time to wait for the condition. Defaults to 10s.
|
// Timeout is the maximum time to wait for the condition. Defaults to 10s.
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
|
@ -57,7 +57,7 @@ func WithTimeout(timeout time.Duration) SettingOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result of a check performed by WaitOn
|
// Result of a check performed by [WaitOn]
|
||||||
type Result interface {
|
type Result interface {
|
||||||
// Error indicates that the check failed and polling should stop, and the
|
// Error indicates that the check failed and polling should stop, and the
|
||||||
// the has failed
|
// the has failed
|
||||||
|
@ -86,20 +86,20 @@ func (r result) Error() error {
|
||||||
return r.err
|
return r.err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue returns a Result that indicates to WaitOn that it should continue
|
// Continue returns a [Result] that indicates to [WaitOn] that it should continue
|
||||||
// polling. The message text will be used as the failure message if the timeout
|
// polling. The message text will be used as the failure message if the timeout
|
||||||
// is reached.
|
// is reached.
|
||||||
func Continue(message string, args ...interface{}) Result {
|
func Continue(message string, args ...interface{}) Result {
|
||||||
return result{message: fmt.Sprintf(message, args...)}
|
return result{message: fmt.Sprintf(message, args...)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success returns a Result where Done() returns true, which indicates to WaitOn
|
// Success returns a [Result] where Done() returns true, which indicates to [WaitOn]
|
||||||
// that it should stop polling and exit without an error.
|
// that it should stop polling and exit without an error.
|
||||||
func Success() Result {
|
func Success() Result {
|
||||||
return result{done: true}
|
return result{done: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error returns a Result that indicates to WaitOn that it should fail the test
|
// Error returns a [Result] that indicates to [WaitOn] that it should fail the test
|
||||||
// and stop polling.
|
// and stop polling.
|
||||||
func Error(err error) Result {
|
func Error(err error) Result {
|
||||||
return result{err: err}
|
return result{err: err}
|
||||||
|
@ -143,9 +143,9 @@ func WaitOn(t TestingT, check Check, pollOps ...SettingOp) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare values using the cmp.Comparison. If the comparison fails return a
|
// Compare values using the [cmp.Comparison]. If the comparison fails return a
|
||||||
// result which indicates to WaitOn that it should continue waiting.
|
// result which indicates to WaitOn that it should continue waiting.
|
||||||
// If the comparison is successful then WaitOn stops polling.
|
// If the comparison is successful then [WaitOn] stops polling.
|
||||||
func Compare(compare cmp.Comparison) Result {
|
func Compare(compare cmp.Comparison) Result {
|
||||||
buf := new(logBuffer)
|
buf := new(logBuffer)
|
||||||
if assert.RunComparison(buf, assert.ArgsAtZeroIndex, compare) {
|
if assert.RunComparison(buf, assert.ArgsAtZeroIndex, compare) {
|
||||||
|
|
|
@ -389,8 +389,8 @@ google.golang.org/protobuf/types/known/timestamppb
|
||||||
# gopkg.in/yaml.v2 v2.4.0
|
# gopkg.in/yaml.v2 v2.4.0
|
||||||
## explicit; go 1.15
|
## explicit; go 1.15
|
||||||
gopkg.in/yaml.v2
|
gopkg.in/yaml.v2
|
||||||
# gotest.tools/v3 v3.4.0
|
# gotest.tools/v3 v3.5.0
|
||||||
## explicit; go 1.13
|
## explicit; go 1.17
|
||||||
gotest.tools/v3/assert
|
gotest.tools/v3/assert
|
||||||
gotest.tools/v3/assert/cmp
|
gotest.tools/v3/assert/cmp
|
||||||
gotest.tools/v3/env
|
gotest.tools/v3/env
|
||||||
|
|
Loading…
Reference in New Issue