Bump github.com/stretchr/testify from 1.10.0 to 1.11.0
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.10.0 to 1.11.0. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.10.0...v1.11.0) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-version: 1.11.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
parent
1fceec374d
commit
642b3bbf92
19 changed files with 673 additions and 336 deletions
2
go.mod
2
go.mod
|
|
@ -22,7 +22,7 @@ require (
|
||||||
github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354
|
github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354
|
||||||
github.com/prometheus/client_golang v1.23.0
|
github.com/prometheus/client_golang v1.23.0
|
||||||
github.com/spf13/cobra v1.9.1
|
github.com/spf13/cobra v1.9.1
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.11.0
|
||||||
golang.org/x/crypto v0.41.0
|
golang.org/x/crypto v0.41.0
|
||||||
golang.org/x/mod v0.27.0
|
golang.org/x/mod v0.27.0
|
||||||
golang.org/x/oauth2 v0.30.0
|
golang.org/x/oauth2 v0.30.0
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -156,8 +156,8 @@ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||||
github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.11.0 h1:ib4sjIrwZKxE5u/Japgo/7SJV3PvgjGiRNAvTVGqQl8=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.11.0/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 h1:xzABM9let0HLLqFypcxvLmlvEciCHL7+Lv+4vwZqecI=
|
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 h1:xzABM9let0HLLqFypcxvLmlvEciCHL7+Lv+4vwZqecI=
|
||||||
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569/go.mod h1:2Ly+NIftZN4de9zRmENdYbvPQeaVIYKWpLFStLFEBgI=
|
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569/go.mod h1:2Ly+NIftZN4de9zRmENdYbvPQeaVIYKWpLFStLFEBgI=
|
||||||
go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFXVw=
|
go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFXVw=
|
||||||
|
|
|
||||||
22
vendor/github.com/stretchr/testify/assert/assertion_compare.go
generated
vendored
22
vendor/github.com/stretchr/testify/assert/assertion_compare.go
generated
vendored
|
|
@ -390,7 +390,8 @@ func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
return compareTwoValues(t, e1, e2, []compareResult{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs...)
|
failMessage := fmt.Sprintf("\"%v\" is not greater than \"%v\"", e1, e2)
|
||||||
|
return compareTwoValues(t, e1, e2, []compareResult{compareGreater}, failMessage, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GreaterOrEqual asserts that the first element is greater than or equal to the second
|
// GreaterOrEqual asserts that the first element is greater than or equal to the second
|
||||||
|
|
@ -403,7 +404,8 @@ func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...in
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
return compareTwoValues(t, e1, e2, []compareResult{compareGreater, compareEqual}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs...)
|
failMessage := fmt.Sprintf("\"%v\" is not greater than or equal to \"%v\"", e1, e2)
|
||||||
|
return compareTwoValues(t, e1, e2, []compareResult{compareGreater, compareEqual}, failMessage, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Less asserts that the first element is less than the second
|
// Less asserts that the first element is less than the second
|
||||||
|
|
@ -415,7 +417,8 @@ func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
return compareTwoValues(t, e1, e2, []compareResult{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs...)
|
failMessage := fmt.Sprintf("\"%v\" is not less than \"%v\"", e1, e2)
|
||||||
|
return compareTwoValues(t, e1, e2, []compareResult{compareLess}, failMessage, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LessOrEqual asserts that the first element is less than or equal to the second
|
// LessOrEqual asserts that the first element is less than or equal to the second
|
||||||
|
|
@ -428,7 +431,8 @@ func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...inter
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
return compareTwoValues(t, e1, e2, []compareResult{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs...)
|
failMessage := fmt.Sprintf("\"%v\" is not less than or equal to \"%v\"", e1, e2)
|
||||||
|
return compareTwoValues(t, e1, e2, []compareResult{compareLess, compareEqual}, failMessage, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Positive asserts that the specified element is positive
|
// Positive asserts that the specified element is positive
|
||||||
|
|
@ -440,7 +444,8 @@ func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
zero := reflect.Zero(reflect.TypeOf(e))
|
zero := reflect.Zero(reflect.TypeOf(e))
|
||||||
return compareTwoValues(t, e, zero.Interface(), []compareResult{compareGreater}, "\"%v\" is not positive", msgAndArgs...)
|
failMessage := fmt.Sprintf("\"%v\" is not positive", e)
|
||||||
|
return compareTwoValues(t, e, zero.Interface(), []compareResult{compareGreater}, failMessage, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negative asserts that the specified element is negative
|
// Negative asserts that the specified element is negative
|
||||||
|
|
@ -452,7 +457,8 @@ func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
zero := reflect.Zero(reflect.TypeOf(e))
|
zero := reflect.Zero(reflect.TypeOf(e))
|
||||||
return compareTwoValues(t, e, zero.Interface(), []compareResult{compareLess}, "\"%v\" is not negative", msgAndArgs...)
|
failMessage := fmt.Sprintf("\"%v\" is not negative", e)
|
||||||
|
return compareTwoValues(t, e, zero.Interface(), []compareResult{compareLess}, failMessage, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedComparesResults []compareResult, failMessage string, msgAndArgs ...interface{}) bool {
|
func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedComparesResults []compareResult, failMessage string, msgAndArgs ...interface{}) bool {
|
||||||
|
|
@ -468,11 +474,11 @@ func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedCompare
|
||||||
|
|
||||||
compareResult, isComparable := compare(e1, e2, e1Kind)
|
compareResult, isComparable := compare(e1, e2, e1Kind)
|
||||||
if !isComparable {
|
if !isComparable {
|
||||||
return Fail(t, fmt.Sprintf("Can not compare type \"%s\"", reflect.TypeOf(e1)), msgAndArgs...)
|
return Fail(t, fmt.Sprintf(`Can not compare type "%T"`, e1), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !containsValue(allowedComparesResults, compareResult) {
|
if !containsValue(allowedComparesResults, compareResult) {
|
||||||
return Fail(t, fmt.Sprintf(failMessage, e1, e2), msgAndArgs...)
|
return Fail(t, failMessage, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
49
vendor/github.com/stretchr/testify/assert/assertion_format.go
generated
vendored
49
vendor/github.com/stretchr/testify/assert/assertion_format.go
generated
vendored
|
|
@ -50,10 +50,19 @@ func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string
|
||||||
return ElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...)
|
return ElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
// Emptyf asserts that the given value is "empty".
|
||||||
// a slice or a channel with len == 0.
|
//
|
||||||
|
// [Zero values] are "empty".
|
||||||
|
//
|
||||||
|
// Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
|
||||||
|
//
|
||||||
|
// Slices, maps and channels with zero length are "empty".
|
||||||
|
//
|
||||||
|
// Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
|
||||||
//
|
//
|
||||||
// assert.Emptyf(t, obj, "error message %s", "formatted")
|
// assert.Emptyf(t, obj, "error message %s", "formatted")
|
||||||
|
//
|
||||||
|
// [Zero values]: https://go.dev/ref/spec#The_zero_value
|
||||||
func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
|
func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -118,9 +127,7 @@ func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg stri
|
||||||
// Errorf asserts that a function returned an error (i.e. not `nil`).
|
// Errorf asserts that a function returned an error (i.e. not `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if assert.Errorf(t, err, "error message %s", "formatted") {
|
// assert.Errorf(t, err, "error message %s", "formatted")
|
||||||
// assert.Equal(t, expectedErrorf, err)
|
|
||||||
// }
|
|
||||||
func Errorf(t TestingT, err error, msg string, args ...interface{}) bool {
|
func Errorf(t TestingT, err error, msg string, args ...interface{}) bool {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -438,7 +445,19 @@ func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interf
|
||||||
return IsNonIncreasing(t, object, append([]interface{}{msg}, args...)...)
|
return IsNonIncreasing(t, object, append([]interface{}{msg}, args...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNotTypef asserts that the specified objects are not of the same type.
|
||||||
|
//
|
||||||
|
// assert.IsNotTypef(t, &NotMyStruct{}, &MyStruct{}, "error message %s", "formatted")
|
||||||
|
func IsNotTypef(t TestingT, theType interface{}, object interface{}, msg string, args ...interface{}) bool {
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return IsNotType(t, theType, object, append([]interface{}{msg}, args...)...)
|
||||||
|
}
|
||||||
|
|
||||||
// IsTypef asserts that the specified objects are of the same type.
|
// IsTypef asserts that the specified objects are of the same type.
|
||||||
|
//
|
||||||
|
// assert.IsTypef(t, &MyStruct{}, &MyStruct{}, "error message %s", "formatted")
|
||||||
func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
|
func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -585,8 +604,7 @@ func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg str
|
||||||
return NotElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...)
|
return NotElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
// NotEmptyf asserts that the specified object is NOT [Empty].
|
||||||
// a slice or a channel with len == 0.
|
|
||||||
//
|
//
|
||||||
// if assert.NotEmptyf(t, obj, "error message %s", "formatted") {
|
// if assert.NotEmptyf(t, obj, "error message %s", "formatted") {
|
||||||
// assert.Equal(t, "two", obj[1])
|
// assert.Equal(t, "two", obj[1])
|
||||||
|
|
@ -693,12 +711,15 @@ func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string,
|
||||||
return NotSame(t, expected, actual, append([]interface{}{msg}, args...)...)
|
return NotSame(t, expected, actual, append([]interface{}{msg}, args...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotSubsetf asserts that the specified list(array, slice...) or map does NOT
|
// NotSubsetf asserts that the list (array, slice, or map) does NOT contain all
|
||||||
// contain all elements given in the specified subset list(array, slice...) or
|
// elements given in the subset (array, slice, or map).
|
||||||
// map.
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted")
|
// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted")
|
||||||
// assert.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
|
// assert.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
|
||||||
|
// assert.NotSubsetf(t, [1, 3, 4], {1: "one", 2: "two"}, "error message %s", "formatted")
|
||||||
|
// assert.NotSubsetf(t, {"x": 1, "y": 2}, ["z"], "error message %s", "formatted")
|
||||||
func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
|
func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -782,11 +803,15 @@ func Samef(t TestingT, expected interface{}, actual interface{}, msg string, arg
|
||||||
return Same(t, expected, actual, append([]interface{}{msg}, args...)...)
|
return Same(t, expected, actual, append([]interface{}{msg}, args...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subsetf asserts that the specified list(array, slice...) or map contains all
|
// Subsetf asserts that the list (array, slice, or map) contains all elements
|
||||||
// elements given in the specified subset list(array, slice...) or map.
|
// given in the subset (array, slice, or map).
|
||||||
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// assert.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted")
|
// assert.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted")
|
||||||
// assert.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
|
// assert.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
|
||||||
|
// assert.Subsetf(t, [1, 2, 3], {1: "one", 2: "two"}, "error message %s", "formatted")
|
||||||
|
// assert.Subsetf(t, {"x": 1, "y": 2}, ["x"], "error message %s", "formatted")
|
||||||
func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
|
func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
|
||||||
98
vendor/github.com/stretchr/testify/assert/assertion_forward.go
generated
vendored
98
vendor/github.com/stretchr/testify/assert/assertion_forward.go
generated
vendored
|
|
@ -92,10 +92,19 @@ func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg st
|
||||||
return ElementsMatchf(a.t, listA, listB, msg, args...)
|
return ElementsMatchf(a.t, listA, listB, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
// Empty asserts that the given value is "empty".
|
||||||
// a slice or a channel with len == 0.
|
//
|
||||||
|
// [Zero values] are "empty".
|
||||||
|
//
|
||||||
|
// Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
|
||||||
|
//
|
||||||
|
// Slices, maps and channels with zero length are "empty".
|
||||||
|
//
|
||||||
|
// Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
|
||||||
//
|
//
|
||||||
// a.Empty(obj)
|
// a.Empty(obj)
|
||||||
|
//
|
||||||
|
// [Zero values]: https://go.dev/ref/spec#The_zero_value
|
||||||
func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -103,10 +112,19 @@ func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Empty(a.t, object, msgAndArgs...)
|
return Empty(a.t, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
// Emptyf asserts that the given value is "empty".
|
||||||
// a slice or a channel with len == 0.
|
//
|
||||||
|
// [Zero values] are "empty".
|
||||||
|
//
|
||||||
|
// Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
|
||||||
|
//
|
||||||
|
// Slices, maps and channels with zero length are "empty".
|
||||||
|
//
|
||||||
|
// Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
|
||||||
//
|
//
|
||||||
// a.Emptyf(obj, "error message %s", "formatted")
|
// a.Emptyf(obj, "error message %s", "formatted")
|
||||||
|
//
|
||||||
|
// [Zero values]: https://go.dev/ref/spec#The_zero_value
|
||||||
func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) bool {
|
func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -225,9 +243,7 @@ func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string
|
||||||
// Error asserts that a function returned an error (i.e. not `nil`).
|
// Error asserts that a function returned an error (i.e. not `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if a.Error(err) {
|
// a.Error(err)
|
||||||
// assert.Equal(t, expectedError, err)
|
|
||||||
// }
|
|
||||||
func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -298,9 +314,7 @@ func (a *Assertions) ErrorIsf(err error, target error, msg string, args ...inter
|
||||||
// Errorf asserts that a function returned an error (i.e. not `nil`).
|
// Errorf asserts that a function returned an error (i.e. not `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if a.Errorf(err, "error message %s", "formatted") {
|
// a.Errorf(err, "error message %s", "formatted")
|
||||||
// assert.Equal(t, expectedErrorf, err)
|
|
||||||
// }
|
|
||||||
func (a *Assertions) Errorf(err error, msg string, args ...interface{}) bool {
|
func (a *Assertions) Errorf(err error, msg string, args ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -868,7 +882,29 @@ func (a *Assertions) IsNonIncreasingf(object interface{}, msg string, args ...in
|
||||||
return IsNonIncreasingf(a.t, object, msg, args...)
|
return IsNonIncreasingf(a.t, object, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNotType asserts that the specified objects are not of the same type.
|
||||||
|
//
|
||||||
|
// a.IsNotType(&NotMyStruct{}, &MyStruct{})
|
||||||
|
func (a *Assertions) IsNotType(theType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
if h, ok := a.t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return IsNotType(a.t, theType, object, msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotTypef asserts that the specified objects are not of the same type.
|
||||||
|
//
|
||||||
|
// a.IsNotTypef(&NotMyStruct{}, &MyStruct{}, "error message %s", "formatted")
|
||||||
|
func (a *Assertions) IsNotTypef(theType interface{}, object interface{}, msg string, args ...interface{}) bool {
|
||||||
|
if h, ok := a.t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return IsNotTypef(a.t, theType, object, msg, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// IsType asserts that the specified objects are of the same type.
|
// IsType asserts that the specified objects are of the same type.
|
||||||
|
//
|
||||||
|
// a.IsType(&MyStruct{}, &MyStruct{})
|
||||||
func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -877,6 +913,8 @@ func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAnd
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsTypef asserts that the specified objects are of the same type.
|
// IsTypef asserts that the specified objects are of the same type.
|
||||||
|
//
|
||||||
|
// a.IsTypef(&MyStruct{}, &MyStruct{}, "error message %s", "formatted")
|
||||||
func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
|
func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1162,8 +1200,7 @@ func (a *Assertions) NotElementsMatchf(listA interface{}, listB interface{}, msg
|
||||||
return NotElementsMatchf(a.t, listA, listB, msg, args...)
|
return NotElementsMatchf(a.t, listA, listB, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
// NotEmpty asserts that the specified object is NOT [Empty].
|
||||||
// a slice or a channel with len == 0.
|
|
||||||
//
|
//
|
||||||
// if a.NotEmpty(obj) {
|
// if a.NotEmpty(obj) {
|
||||||
// assert.Equal(t, "two", obj[1])
|
// assert.Equal(t, "two", obj[1])
|
||||||
|
|
@ -1175,8 +1212,7 @@ func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) boo
|
||||||
return NotEmpty(a.t, object, msgAndArgs...)
|
return NotEmpty(a.t, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
// NotEmptyf asserts that the specified object is NOT [Empty].
|
||||||
// a slice or a channel with len == 0.
|
|
||||||
//
|
//
|
||||||
// if a.NotEmptyf(obj, "error message %s", "formatted") {
|
// if a.NotEmptyf(obj, "error message %s", "formatted") {
|
||||||
// assert.Equal(t, "two", obj[1])
|
// assert.Equal(t, "two", obj[1])
|
||||||
|
|
@ -1378,12 +1414,15 @@ func (a *Assertions) NotSamef(expected interface{}, actual interface{}, msg stri
|
||||||
return NotSamef(a.t, expected, actual, msg, args...)
|
return NotSamef(a.t, expected, actual, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotSubset asserts that the specified list(array, slice...) or map does NOT
|
// NotSubset asserts that the list (array, slice, or map) does NOT contain all
|
||||||
// contain all elements given in the specified subset list(array, slice...) or
|
// elements given in the subset (array, slice, or map).
|
||||||
// map.
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// a.NotSubset([1, 3, 4], [1, 2])
|
// a.NotSubset([1, 3, 4], [1, 2])
|
||||||
// a.NotSubset({"x": 1, "y": 2}, {"z": 3})
|
// a.NotSubset({"x": 1, "y": 2}, {"z": 3})
|
||||||
|
// a.NotSubset([1, 3, 4], {1: "one", 2: "two"})
|
||||||
|
// a.NotSubset({"x": 1, "y": 2}, ["z"])
|
||||||
func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1391,12 +1430,15 @@ func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs
|
||||||
return NotSubset(a.t, list, subset, msgAndArgs...)
|
return NotSubset(a.t, list, subset, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotSubsetf asserts that the specified list(array, slice...) or map does NOT
|
// NotSubsetf asserts that the list (array, slice, or map) does NOT contain all
|
||||||
// contain all elements given in the specified subset list(array, slice...) or
|
// elements given in the subset (array, slice, or map).
|
||||||
// map.
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// a.NotSubsetf([1, 3, 4], [1, 2], "error message %s", "formatted")
|
// a.NotSubsetf([1, 3, 4], [1, 2], "error message %s", "formatted")
|
||||||
// a.NotSubsetf({"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
|
// a.NotSubsetf({"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
|
||||||
|
// a.NotSubsetf([1, 3, 4], {1: "one", 2: "two"}, "error message %s", "formatted")
|
||||||
|
// a.NotSubsetf({"x": 1, "y": 2}, ["z"], "error message %s", "formatted")
|
||||||
func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {
|
func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1556,11 +1598,15 @@ func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string,
|
||||||
return Samef(a.t, expected, actual, msg, args...)
|
return Samef(a.t, expected, actual, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subset asserts that the specified list(array, slice...) or map contains all
|
// Subset asserts that the list (array, slice, or map) contains all elements
|
||||||
// elements given in the specified subset list(array, slice...) or map.
|
// given in the subset (array, slice, or map).
|
||||||
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// a.Subset([1, 2, 3], [1, 2])
|
// a.Subset([1, 2, 3], [1, 2])
|
||||||
// a.Subset({"x": 1, "y": 2}, {"x": 1})
|
// a.Subset({"x": 1, "y": 2}, {"x": 1})
|
||||||
|
// a.Subset([1, 2, 3], {1: "one", 2: "two"})
|
||||||
|
// a.Subset({"x": 1, "y": 2}, ["x"])
|
||||||
func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1568,11 +1614,15 @@ func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...
|
||||||
return Subset(a.t, list, subset, msgAndArgs...)
|
return Subset(a.t, list, subset, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subsetf asserts that the specified list(array, slice...) or map contains all
|
// Subsetf asserts that the list (array, slice, or map) contains all elements
|
||||||
// elements given in the specified subset list(array, slice...) or map.
|
// given in the subset (array, slice, or map).
|
||||||
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// a.Subsetf([1, 2, 3], [1, 2], "error message %s", "formatted")
|
// a.Subsetf([1, 2, 3], [1, 2], "error message %s", "formatted")
|
||||||
// a.Subsetf({"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
|
// a.Subsetf({"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
|
||||||
|
// a.Subsetf([1, 2, 3], {1: "one", 2: "two"}, "error message %s", "formatted")
|
||||||
|
// a.Subsetf({"x": 1, "y": 2}, ["x"], "error message %s", "formatted")
|
||||||
func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {
|
func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
|
||||||
2
vendor/github.com/stretchr/testify/assert/assertion_order.go
generated
vendored
2
vendor/github.com/stretchr/testify/assert/assertion_order.go
generated
vendored
|
|
@ -33,7 +33,7 @@ func isOrdered(t TestingT, object interface{}, allowedComparesResults []compareR
|
||||||
compareResult, isComparable := compare(prevValueInterface, valueInterface, firstValueKind)
|
compareResult, isComparable := compare(prevValueInterface, valueInterface, firstValueKind)
|
||||||
|
|
||||||
if !isComparable {
|
if !isComparable {
|
||||||
return Fail(t, fmt.Sprintf("Can not compare type \"%s\" and \"%s\"", reflect.TypeOf(value), reflect.TypeOf(prevValue)), msgAndArgs...)
|
return Fail(t, fmt.Sprintf(`Can not compare type "%T" and "%T"`, value, prevValue), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !containsValue(allowedComparesResults, compareResult) {
|
if !containsValue(allowedComparesResults, compareResult) {
|
||||||
|
|
|
||||||
305
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
305
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
|
|
@ -210,22 +210,32 @@ the problem actually occurred in calling code.*/
|
||||||
// of each stack frame leading from the current test to the assert call that
|
// of each stack frame leading from the current test to the assert call that
|
||||||
// failed.
|
// failed.
|
||||||
func CallerInfo() []string {
|
func CallerInfo() []string {
|
||||||
|
|
||||||
var pc uintptr
|
var pc uintptr
|
||||||
var ok bool
|
|
||||||
var file string
|
var file string
|
||||||
var line int
|
var line int
|
||||||
var name string
|
var name string
|
||||||
|
|
||||||
|
const stackFrameBufferSize = 10
|
||||||
|
pcs := make([]uintptr, stackFrameBufferSize)
|
||||||
|
|
||||||
callers := []string{}
|
callers := []string{}
|
||||||
for i := 0; ; i++ {
|
offset := 1
|
||||||
pc, file, line, ok = runtime.Caller(i)
|
|
||||||
if !ok {
|
for {
|
||||||
// The breaks below failed to terminate the loop, and we ran off the
|
n := runtime.Callers(offset, pcs)
|
||||||
// end of the call stack.
|
|
||||||
|
if n == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frames := runtime.CallersFrames(pcs[:n])
|
||||||
|
|
||||||
|
for {
|
||||||
|
frame, more := frames.Next()
|
||||||
|
pc = frame.PC
|
||||||
|
file = frame.File
|
||||||
|
line = frame.Line
|
||||||
|
|
||||||
// This is a huge edge case, but it will panic if this is the case, see #180
|
// This is a huge edge case, but it will panic if this is the case, see #180
|
||||||
if file == "<autogenerated>" {
|
if file == "<autogenerated>" {
|
||||||
break
|
break
|
||||||
|
|
@ -256,13 +266,21 @@ func CallerInfo() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop the package
|
// Drop the package
|
||||||
segments := strings.Split(name, ".")
|
dotPos := strings.LastIndexByte(name, '.')
|
||||||
name = segments[len(segments)-1]
|
name = name[dotPos+1:]
|
||||||
if isTest(name, "Test") ||
|
if isTest(name, "Test") ||
|
||||||
isTest(name, "Benchmark") ||
|
isTest(name, "Benchmark") ||
|
||||||
isTest(name, "Example") {
|
isTest(name, "Example") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !more {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next batch
|
||||||
|
offset += cap(pcs)
|
||||||
}
|
}
|
||||||
|
|
||||||
return callers
|
return callers
|
||||||
|
|
@ -437,18 +455,35 @@ func NotImplements(t TestingT, interfaceObject interface{}, object interface{},
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isType(expectedType, object interface{}) bool {
|
||||||
|
return ObjectsAreEqual(reflect.TypeOf(object), reflect.TypeOf(expectedType))
|
||||||
|
}
|
||||||
|
|
||||||
// IsType asserts that the specified objects are of the same type.
|
// IsType asserts that the specified objects are of the same type.
|
||||||
func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
|
//
|
||||||
|
// assert.IsType(t, &MyStruct{}, &MyStruct{})
|
||||||
|
func IsType(t TestingT, expectedType, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
if isType(expectedType, object) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
|
return Fail(t, fmt.Sprintf("Object expected to be of type %T, but was %T", expectedType, object), msgAndArgs...)
|
||||||
if !ObjectsAreEqual(reflect.TypeOf(object), reflect.TypeOf(expectedType)) {
|
|
||||||
return Fail(t, fmt.Sprintf("Object expected to be of type %v, but was %v", reflect.TypeOf(expectedType), reflect.TypeOf(object)), msgAndArgs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNotType asserts that the specified objects are not of the same type.
|
||||||
|
//
|
||||||
|
// assert.IsNotType(t, &NotMyStruct{}, &MyStruct{})
|
||||||
|
func IsNotType(t TestingT, theType, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
if !isType(theType, object) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return Fail(t, fmt.Sprintf("Object type expected to be different than %T", theType), msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
// Equal asserts that two objects are equal.
|
// Equal asserts that two objects are equal.
|
||||||
//
|
//
|
||||||
|
|
@ -475,7 +510,6 @@ func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateEqualArgs checks whether provided arguments can be safely used in the
|
// validateEqualArgs checks whether provided arguments can be safely used in the
|
||||||
|
|
@ -510,8 +544,9 @@ func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) b
|
||||||
if !same {
|
if !same {
|
||||||
// both are pointers but not the same type & pointing to the same address
|
// both are pointers but not the same type & pointing to the same address
|
||||||
return Fail(t, fmt.Sprintf("Not same: \n"+
|
return Fail(t, fmt.Sprintf("Not same: \n"+
|
||||||
"expected: %p %#v\n"+
|
"expected: %p %#[1]v\n"+
|
||||||
"actual : %p %#v", expected, expected, actual, actual), msgAndArgs...)
|
"actual : %p %#[2]v",
|
||||||
|
expected, actual), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
@ -536,8 +571,8 @@ func NotSame(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}
|
||||||
|
|
||||||
if same {
|
if same {
|
||||||
return Fail(t, fmt.Sprintf(
|
return Fail(t, fmt.Sprintf(
|
||||||
"Expected and actual point to the same object: %p %#v",
|
"Expected and actual point to the same object: %p %#[1]v",
|
||||||
expected, expected), msgAndArgs...)
|
expected), msgAndArgs...)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -610,7 +645,6 @@ func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interfa
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EqualExportedValues asserts that the types of two objects are equal and their public
|
// EqualExportedValues asserts that the types of two objects are equal and their public
|
||||||
|
|
@ -665,7 +699,6 @@ func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Equal(t, expected, actual, msgAndArgs...)
|
return Equal(t, expected, actual, msgAndArgs...)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotNil asserts that the specified object is not nil.
|
// NotNil asserts that the specified object is not nil.
|
||||||
|
|
@ -715,37 +748,45 @@ func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
|
||||||
// isEmpty gets whether the specified object is considered empty or not.
|
// isEmpty gets whether the specified object is considered empty or not.
|
||||||
func isEmpty(object interface{}) bool {
|
func isEmpty(object interface{}) bool {
|
||||||
|
|
||||||
// get nil case out of the way
|
// get nil case out of the way
|
||||||
if object == nil {
|
if object == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
objValue := reflect.ValueOf(object)
|
return isEmptyValue(reflect.ValueOf(object))
|
||||||
|
}
|
||||||
|
|
||||||
switch objValue.Kind() {
|
// isEmptyValue gets whether the specified reflect.Value is considered empty or not.
|
||||||
// collection types are empty when they have no element
|
func isEmptyValue(objValue reflect.Value) bool {
|
||||||
case reflect.Chan, reflect.Map, reflect.Slice:
|
if objValue.IsZero() {
|
||||||
return objValue.Len() == 0
|
|
||||||
// pointers are empty if nil or if the value they point to is empty
|
|
||||||
case reflect.Ptr:
|
|
||||||
if objValue.IsNil() {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
deref := objValue.Elem().Interface()
|
// Special cases of non-zero values that we consider empty
|
||||||
return isEmpty(deref)
|
switch objValue.Kind() {
|
||||||
// for all other types, compare against the zero value
|
// collection types are empty when they have no element
|
||||||
// array types are empty when they match their zero-initialized state
|
// Note: array types are empty when they match their zero-initialized state.
|
||||||
default:
|
case reflect.Chan, reflect.Map, reflect.Slice:
|
||||||
zero := reflect.Zero(objValue.Type())
|
return objValue.Len() == 0
|
||||||
return reflect.DeepEqual(object, zero.Interface())
|
// non-nil pointers are empty if the value they point to is empty
|
||||||
|
case reflect.Ptr:
|
||||||
|
return isEmptyValue(objValue.Elem())
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
// Empty asserts that the given value is "empty".
|
||||||
// a slice or a channel with len == 0.
|
//
|
||||||
|
// [Zero values] are "empty".
|
||||||
|
//
|
||||||
|
// Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
|
||||||
|
//
|
||||||
|
// Slices, maps and channels with zero length are "empty".
|
||||||
|
//
|
||||||
|
// Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
|
||||||
//
|
//
|
||||||
// assert.Empty(t, obj)
|
// assert.Empty(t, obj)
|
||||||
|
//
|
||||||
|
// [Zero values]: https://go.dev/ref/spec#The_zero_value
|
||||||
func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
pass := isEmpty(object)
|
pass := isEmpty(object)
|
||||||
if !pass {
|
if !pass {
|
||||||
|
|
@ -756,11 +797,9 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
return pass
|
return pass
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
// NotEmpty asserts that the specified object is NOT [Empty].
|
||||||
// a slice or a channel with len == 0.
|
|
||||||
//
|
//
|
||||||
// if assert.NotEmpty(t, obj) {
|
// if assert.NotEmpty(t, obj) {
|
||||||
// assert.Equal(t, "two", obj[1])
|
// assert.Equal(t, "two", obj[1])
|
||||||
|
|
@ -775,7 +814,6 @@ func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
return pass
|
return pass
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getLen tries to get the length of an object.
|
// getLen tries to get the length of an object.
|
||||||
|
|
@ -819,7 +857,6 @@ func True(t TestingT, value bool, msgAndArgs ...interface{}) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// False asserts that the specified value is false.
|
// False asserts that the specified value is false.
|
||||||
|
|
@ -834,7 +871,6 @@ func False(t TestingT, value bool, msgAndArgs ...interface{}) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEqual asserts that the specified values are NOT equal.
|
// NotEqual asserts that the specified values are NOT equal.
|
||||||
|
|
@ -857,7 +893,6 @@ func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEqualValues asserts that two objects are not equal even when converted to the same type
|
// NotEqualValues asserts that two objects are not equal even when converted to the same type
|
||||||
|
|
@ -880,7 +915,6 @@ func NotEqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...inte
|
||||||
// return (true, false) if element was not found.
|
// return (true, false) if element was not found.
|
||||||
// return (true, true) if element was found.
|
// return (true, true) if element was found.
|
||||||
func containsElement(list interface{}, element interface{}) (ok, found bool) {
|
func containsElement(list interface{}, element interface{}) (ok, found bool) {
|
||||||
|
|
||||||
listValue := reflect.ValueOf(list)
|
listValue := reflect.ValueOf(list)
|
||||||
listType := reflect.TypeOf(list)
|
listType := reflect.TypeOf(list)
|
||||||
if listType == nil {
|
if listType == nil {
|
||||||
|
|
@ -915,7 +949,6 @@ func containsElement(list interface{}, element interface{}) (ok, found bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true, false
|
return true, false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contains asserts that the specified string, list(array, slice...) or map contains the
|
// Contains asserts that the specified string, list(array, slice...) or map contains the
|
||||||
|
|
@ -938,7 +971,6 @@ func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bo
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
|
// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
|
||||||
|
|
@ -961,14 +993,17 @@ func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subset asserts that the specified list(array, slice...) or map contains all
|
// Subset asserts that the list (array, slice, or map) contains all elements
|
||||||
// elements given in the specified subset list(array, slice...) or map.
|
// given in the subset (array, slice, or map).
|
||||||
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// assert.Subset(t, [1, 2, 3], [1, 2])
|
// assert.Subset(t, [1, 2, 3], [1, 2])
|
||||||
// assert.Subset(t, {"x": 1, "y": 2}, {"x": 1})
|
// assert.Subset(t, {"x": 1, "y": 2}, {"x": 1})
|
||||||
|
// assert.Subset(t, [1, 2, 3], {1: "one", 2: "two"})
|
||||||
|
// assert.Subset(t, {"x": 1, "y": 2}, ["x"])
|
||||||
func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
|
func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -983,7 +1018,7 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
|
||||||
}
|
}
|
||||||
|
|
||||||
subsetKind := reflect.TypeOf(subset).Kind()
|
subsetKind := reflect.TypeOf(subset).Kind()
|
||||||
if subsetKind != reflect.Array && subsetKind != reflect.Slice && listKind != reflect.Map {
|
if subsetKind != reflect.Array && subsetKind != reflect.Slice && subsetKind != reflect.Map {
|
||||||
return Fail(t, fmt.Sprintf("%q has an unsupported type %s", subset, subsetKind), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("%q has an unsupported type %s", subset, subsetKind), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1007,6 +1042,13 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
|
||||||
}
|
}
|
||||||
|
|
||||||
subsetList := reflect.ValueOf(subset)
|
subsetList := reflect.ValueOf(subset)
|
||||||
|
if subsetKind == reflect.Map {
|
||||||
|
keys := make([]interface{}, subsetList.Len())
|
||||||
|
for idx, key := range subsetList.MapKeys() {
|
||||||
|
keys[idx] = key.Interface()
|
||||||
|
}
|
||||||
|
subsetList = reflect.ValueOf(keys)
|
||||||
|
}
|
||||||
for i := 0; i < subsetList.Len(); i++ {
|
for i := 0; i < subsetList.Len(); i++ {
|
||||||
element := subsetList.Index(i).Interface()
|
element := subsetList.Index(i).Interface()
|
||||||
ok, found := containsElement(list, element)
|
ok, found := containsElement(list, element)
|
||||||
|
|
@ -1021,12 +1063,15 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotSubset asserts that the specified list(array, slice...) or map does NOT
|
// NotSubset asserts that the list (array, slice, or map) does NOT contain all
|
||||||
// contain all elements given in the specified subset list(array, slice...) or
|
// elements given in the subset (array, slice, or map).
|
||||||
// map.
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// assert.NotSubset(t, [1, 3, 4], [1, 2])
|
// assert.NotSubset(t, [1, 3, 4], [1, 2])
|
||||||
// assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
|
// assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
|
||||||
|
// assert.NotSubset(t, [1, 3, 4], {1: "one", 2: "two"})
|
||||||
|
// assert.NotSubset(t, {"x": 1, "y": 2}, ["z"])
|
||||||
func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
|
func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1041,7 +1086,7 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
subsetKind := reflect.TypeOf(subset).Kind()
|
subsetKind := reflect.TypeOf(subset).Kind()
|
||||||
if subsetKind != reflect.Array && subsetKind != reflect.Slice && listKind != reflect.Map {
|
if subsetKind != reflect.Array && subsetKind != reflect.Slice && subsetKind != reflect.Map {
|
||||||
return Fail(t, fmt.Sprintf("%q has an unsupported type %s", subset, subsetKind), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("%q has an unsupported type %s", subset, subsetKind), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1065,11 +1110,18 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
subsetList := reflect.ValueOf(subset)
|
subsetList := reflect.ValueOf(subset)
|
||||||
|
if subsetKind == reflect.Map {
|
||||||
|
keys := make([]interface{}, subsetList.Len())
|
||||||
|
for idx, key := range subsetList.MapKeys() {
|
||||||
|
keys[idx] = key.Interface()
|
||||||
|
}
|
||||||
|
subsetList = reflect.ValueOf(keys)
|
||||||
|
}
|
||||||
for i := 0; i < subsetList.Len(); i++ {
|
for i := 0; i < subsetList.Len(); i++ {
|
||||||
element := subsetList.Index(i).Interface()
|
element := subsetList.Index(i).Interface()
|
||||||
ok, found := containsElement(list, element)
|
ok, found := containsElement(list, element)
|
||||||
if !ok {
|
if !ok {
|
||||||
return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", list), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("%q could not be applied builtin len()", list), msgAndArgs...)
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
return true
|
return true
|
||||||
|
|
@ -1592,9 +1644,7 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool {
|
||||||
// Error asserts that a function returned an error (i.e. not `nil`).
|
// Error asserts that a function returned an error (i.e. not `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if assert.Error(t, err) {
|
// assert.Error(t, err)
|
||||||
// assert.Equal(t, expectedError, err)
|
|
||||||
// }
|
|
||||||
func Error(t TestingT, err error, msgAndArgs ...interface{}) bool {
|
func Error(t TestingT, err error, msgAndArgs ...interface{}) bool {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
|
|
@ -1667,7 +1717,6 @@ func matchRegexp(rx interface{}, str interface{}) bool {
|
||||||
default:
|
default:
|
||||||
return r.MatchString(fmt.Sprint(v))
|
return r.MatchString(fmt.Sprint(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regexp asserts that a specified regexp matches a string.
|
// Regexp asserts that a specified regexp matches a string.
|
||||||
|
|
@ -1703,7 +1752,6 @@ func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interf
|
||||||
}
|
}
|
||||||
|
|
||||||
return !match
|
return !match
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zero asserts that i is the zero value for its type.
|
// Zero asserts that i is the zero value for its type.
|
||||||
|
|
@ -1814,6 +1862,11 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
|
||||||
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shortcut if same bytes
|
||||||
|
if actual == expected {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil {
|
if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil {
|
||||||
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
@ -1832,6 +1885,11 @@ func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
|
||||||
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid yaml.\nYAML parsing error: '%s'", expected, err.Error()), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid yaml.\nYAML parsing error: '%s'", expected, err.Error()), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shortcut if same bytes
|
||||||
|
if actual == expected {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if err := yaml.Unmarshal([]byte(actual), &actualYAMLAsInterface); err != nil {
|
if err := yaml.Unmarshal([]byte(actual), &actualYAMLAsInterface); err != nil {
|
||||||
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid yaml.\nYAML error: '%s'", actual, err.Error()), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid yaml.\nYAML error: '%s'", actual, err.Error()), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
@ -1933,6 +1991,7 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan bool, 1)
|
ch := make(chan bool, 1)
|
||||||
|
checkCond := func() { ch <- condition() }
|
||||||
|
|
||||||
timer := time.NewTimer(waitFor)
|
timer := time.NewTimer(waitFor)
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
|
|
@ -1940,18 +1999,23 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t
|
||||||
ticker := time.NewTicker(tick)
|
ticker := time.NewTicker(tick)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for tick := ticker.C; ; {
|
var tickC <-chan time.Time
|
||||||
|
|
||||||
|
// Check the condition once first on the initial call.
|
||||||
|
go checkCond()
|
||||||
|
|
||||||
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
return Fail(t, "Condition never satisfied", msgAndArgs...)
|
return Fail(t, "Condition never satisfied", msgAndArgs...)
|
||||||
case <-tick:
|
case <-tickC:
|
||||||
tick = nil
|
tickC = nil
|
||||||
go func() { ch <- condition() }()
|
go checkCond()
|
||||||
case v := <-ch:
|
case v := <-ch:
|
||||||
if v {
|
if v {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
tick = ticker.C
|
tickC = ticker.C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1964,6 +2028,9 @@ type CollectT struct {
|
||||||
errors []error
|
errors []error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper is like [testing.T.Helper] but does nothing.
|
||||||
|
func (CollectT) Helper() {}
|
||||||
|
|
||||||
// Errorf collects the error.
|
// Errorf collects the error.
|
||||||
func (c *CollectT) Errorf(format string, args ...interface{}) {
|
func (c *CollectT) Errorf(format string, args ...interface{}) {
|
||||||
c.errors = append(c.errors, fmt.Errorf(format, args...))
|
c.errors = append(c.errors, fmt.Errorf(format, args...))
|
||||||
|
|
@ -2021,35 +2088,42 @@ func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time
|
||||||
var lastFinishedTickErrs []error
|
var lastFinishedTickErrs []error
|
||||||
ch := make(chan *CollectT, 1)
|
ch := make(chan *CollectT, 1)
|
||||||
|
|
||||||
|
checkCond := func() {
|
||||||
|
collect := new(CollectT)
|
||||||
|
defer func() {
|
||||||
|
ch <- collect
|
||||||
|
}()
|
||||||
|
condition(collect)
|
||||||
|
}
|
||||||
|
|
||||||
timer := time.NewTimer(waitFor)
|
timer := time.NewTimer(waitFor)
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
|
|
||||||
ticker := time.NewTicker(tick)
|
ticker := time.NewTicker(tick)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for tick := ticker.C; ; {
|
var tickC <-chan time.Time
|
||||||
|
|
||||||
|
// Check the condition once first on the initial call.
|
||||||
|
go checkCond()
|
||||||
|
|
||||||
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
for _, err := range lastFinishedTickErrs {
|
for _, err := range lastFinishedTickErrs {
|
||||||
t.Errorf("%v", err)
|
t.Errorf("%v", err)
|
||||||
}
|
}
|
||||||
return Fail(t, "Condition never satisfied", msgAndArgs...)
|
return Fail(t, "Condition never satisfied", msgAndArgs...)
|
||||||
case <-tick:
|
case <-tickC:
|
||||||
tick = nil
|
tickC = nil
|
||||||
go func() {
|
go checkCond()
|
||||||
collect := new(CollectT)
|
|
||||||
defer func() {
|
|
||||||
ch <- collect
|
|
||||||
}()
|
|
||||||
condition(collect)
|
|
||||||
}()
|
|
||||||
case collect := <-ch:
|
case collect := <-ch:
|
||||||
if !collect.failed() {
|
if !collect.failed() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// Keep the errors from the last ended condition, so that they can be copied to t if timeout is reached.
|
// Keep the errors from the last ended condition, so that they can be copied to t if timeout is reached.
|
||||||
lastFinishedTickErrs = collect.errors
|
lastFinishedTickErrs = collect.errors
|
||||||
tick = ticker.C
|
tickC = ticker.C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2064,6 +2138,7 @@ func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.D
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan bool, 1)
|
ch := make(chan bool, 1)
|
||||||
|
checkCond := func() { ch <- condition() }
|
||||||
|
|
||||||
timer := time.NewTimer(waitFor)
|
timer := time.NewTimer(waitFor)
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
|
|
@ -2071,18 +2146,23 @@ func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.D
|
||||||
ticker := time.NewTicker(tick)
|
ticker := time.NewTicker(tick)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for tick := ticker.C; ; {
|
var tickC <-chan time.Time
|
||||||
|
|
||||||
|
// Check the condition once first on the initial call.
|
||||||
|
go checkCond()
|
||||||
|
|
||||||
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
return true
|
return true
|
||||||
case <-tick:
|
case <-tickC:
|
||||||
tick = nil
|
tickC = nil
|
||||||
go func() { ch <- condition() }()
|
go checkCond()
|
||||||
case v := <-ch:
|
case v := <-ch:
|
||||||
if v {
|
if v {
|
||||||
return Fail(t, "Condition satisfied", msgAndArgs...)
|
return Fail(t, "Condition satisfied", msgAndArgs...)
|
||||||
}
|
}
|
||||||
tick = ticker.C
|
tickC = ticker.C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2100,9 +2180,12 @@ func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool {
|
||||||
var expectedText string
|
var expectedText string
|
||||||
if target != nil {
|
if target != nil {
|
||||||
expectedText = target.Error()
|
expectedText = target.Error()
|
||||||
|
if err == nil {
|
||||||
|
return Fail(t, fmt.Sprintf("Expected error with %q in chain but got nil.", expectedText), msgAndArgs...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chain := buildErrorChainString(err)
|
chain := buildErrorChainString(err, false)
|
||||||
|
|
||||||
return Fail(t, fmt.Sprintf("Target error should be in err chain:\n"+
|
return Fail(t, fmt.Sprintf("Target error should be in err chain:\n"+
|
||||||
"expected: %q\n"+
|
"expected: %q\n"+
|
||||||
|
|
@ -2125,7 +2208,7 @@ func NotErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool {
|
||||||
expectedText = target.Error()
|
expectedText = target.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
chain := buildErrorChainString(err)
|
chain := buildErrorChainString(err, false)
|
||||||
|
|
||||||
return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+
|
return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+
|
||||||
"found: %q\n"+
|
"found: %q\n"+
|
||||||
|
|
@ -2143,11 +2226,17 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
chain := buildErrorChainString(err)
|
expectedType := reflect.TypeOf(target).Elem().String()
|
||||||
|
if err == nil {
|
||||||
|
return Fail(t, fmt.Sprintf("An error is expected but got nil.\n"+
|
||||||
|
"expected: %s", expectedType), msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
chain := buildErrorChainString(err, true)
|
||||||
|
|
||||||
return Fail(t, fmt.Sprintf("Should be in error chain:\n"+
|
return Fail(t, fmt.Sprintf("Should be in error chain:\n"+
|
||||||
"expected: %q\n"+
|
"expected: %s\n"+
|
||||||
"in chain: %s", target, chain,
|
"in chain: %s", expectedType, chain,
|
||||||
), msgAndArgs...)
|
), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2161,24 +2250,46 @@ func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interfa
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
chain := buildErrorChainString(err)
|
chain := buildErrorChainString(err, true)
|
||||||
|
|
||||||
return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+
|
return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+
|
||||||
"found: %q\n"+
|
"found: %s\n"+
|
||||||
"in chain: %s", target, chain,
|
"in chain: %s", reflect.TypeOf(target).Elem().String(), chain,
|
||||||
), msgAndArgs...)
|
), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildErrorChainString(err error) string {
|
func unwrapAll(err error) (errs []error) {
|
||||||
|
errs = append(errs, err)
|
||||||
|
switch x := err.(type) {
|
||||||
|
case interface{ Unwrap() error }:
|
||||||
|
err = x.Unwrap()
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
errs = append(errs, unwrapAll(err)...)
|
||||||
|
case interface{ Unwrap() []error }:
|
||||||
|
for _, err := range x.Unwrap() {
|
||||||
|
errs = append(errs, unwrapAll(err)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildErrorChainString(err error, withType bool) string {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
e := errors.Unwrap(err)
|
var chain string
|
||||||
chain := fmt.Sprintf("%q", err.Error())
|
errs := unwrapAll(err)
|
||||||
for e != nil {
|
for i := range errs {
|
||||||
chain += fmt.Sprintf("\n\t%q", e.Error())
|
if i != 0 {
|
||||||
e = errors.Unwrap(e)
|
chain += "\n\t"
|
||||||
|
}
|
||||||
|
chain += fmt.Sprintf("%q", errs[i].Error())
|
||||||
|
if withType {
|
||||||
|
chain += fmt.Sprintf(" (%T)", errs[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return chain
|
return chain
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
vendor/github.com/stretchr/testify/assert/doc.go
generated
vendored
4
vendor/github.com/stretchr/testify/assert/doc.go
generated
vendored
|
|
@ -1,5 +1,9 @@
|
||||||
// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
|
// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
|
||||||
//
|
//
|
||||||
|
// # Note
|
||||||
|
//
|
||||||
|
// All functions in this package return a bool value indicating whether the assertion has passed.
|
||||||
|
//
|
||||||
// # Example Usage
|
// # Example Usage
|
||||||
//
|
//
|
||||||
// The following is a complete example using assert in a standard test function:
|
// The following is a complete example using assert in a standard test function:
|
||||||
|
|
|
||||||
4
vendor/github.com/stretchr/testify/assert/http_assertions.go
generated
vendored
4
vendor/github.com/stretchr/testify/assert/http_assertions.go
generated
vendored
|
|
@ -138,7 +138,7 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string,
|
||||||
|
|
||||||
contains := strings.Contains(body, fmt.Sprint(str))
|
contains := strings.Contains(body, fmt.Sprint(str))
|
||||||
if !contains {
|
if !contains {
|
||||||
Fail(t, fmt.Sprintf("Expected response body for \"%s\" to contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body), msgAndArgs...)
|
Fail(t, fmt.Sprintf("Expected response body for %q to contain %q but found %q", url+"?"+values.Encode(), str, body), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return contains
|
return contains
|
||||||
|
|
@ -158,7 +158,7 @@ func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url strin
|
||||||
|
|
||||||
contains := strings.Contains(body, fmt.Sprint(str))
|
contains := strings.Contains(body, fmt.Sprint(str))
|
||||||
if contains {
|
if contains {
|
||||||
Fail(t, fmt.Sprintf("Expected response body for \"%s\" to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body), msgAndArgs...)
|
Fail(t, fmt.Sprintf("Expected response body for %q to NOT contain %q but found %q", url+"?"+values.Encode(), str, body), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return !contains
|
return !contains
|
||||||
|
|
|
||||||
1
vendor/github.com/stretchr/testify/assert/yaml/yaml_custom.go
generated
vendored
1
vendor/github.com/stretchr/testify/assert/yaml/yaml_custom.go
generated
vendored
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build testify_yaml_custom && !testify_yaml_fail && !testify_yaml_default
|
//go:build testify_yaml_custom && !testify_yaml_fail && !testify_yaml_default
|
||||||
// +build testify_yaml_custom,!testify_yaml_fail,!testify_yaml_default
|
|
||||||
|
|
||||||
// Package yaml is an implementation of YAML functions that calls a pluggable implementation.
|
// Package yaml is an implementation of YAML functions that calls a pluggable implementation.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
1
vendor/github.com/stretchr/testify/assert/yaml/yaml_default.go
generated
vendored
1
vendor/github.com/stretchr/testify/assert/yaml/yaml_default.go
generated
vendored
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build !testify_yaml_fail && !testify_yaml_custom
|
//go:build !testify_yaml_fail && !testify_yaml_custom
|
||||||
// +build !testify_yaml_fail,!testify_yaml_custom
|
|
||||||
|
|
||||||
// Package yaml is just an indirection to handle YAML deserialization.
|
// Package yaml is just an indirection to handle YAML deserialization.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
1
vendor/github.com/stretchr/testify/assert/yaml/yaml_fail.go
generated
vendored
1
vendor/github.com/stretchr/testify/assert/yaml/yaml_fail.go
generated
vendored
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build testify_yaml_fail && !testify_yaml_custom && !testify_yaml_default
|
//go:build testify_yaml_fail && !testify_yaml_custom && !testify_yaml_default
|
||||||
// +build testify_yaml_fail,!testify_yaml_custom,!testify_yaml_default
|
|
||||||
|
|
||||||
// Package yaml is an implementation of YAML functions that always fail.
|
// Package yaml is an implementation of YAML functions that always fail.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
94
vendor/github.com/stretchr/testify/mock/mock.go
generated
vendored
94
vendor/github.com/stretchr/testify/mock/mock.go
generated
vendored
|
|
@ -208,9 +208,16 @@ func (c *Call) On(methodName string, arguments ...interface{}) *Call {
|
||||||
return c.Parent.On(methodName, arguments...)
|
return c.Parent.On(methodName, arguments...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unset removes a mock handler from being called.
|
// Unset removes all mock handlers that satisfy the call instance arguments from being
|
||||||
|
// called. Only supported on call instances with static input arguments.
|
||||||
//
|
//
|
||||||
// test.On("func", mock.Anything).Unset()
|
// For example, the only handler remaining after the following would be "MyMethod(2, 2)":
|
||||||
|
//
|
||||||
|
// Mock.
|
||||||
|
// On("MyMethod", 2, 2).Return(0).
|
||||||
|
// On("MyMethod", 3, 3).Return(0).
|
||||||
|
// On("MyMethod", Anything, Anything).Return(0)
|
||||||
|
// Mock.On("MyMethod", 3, 3).Unset()
|
||||||
func (c *Call) Unset() *Call {
|
func (c *Call) Unset() *Call {
|
||||||
var unlockOnce sync.Once
|
var unlockOnce sync.Once
|
||||||
|
|
||||||
|
|
@ -331,7 +338,10 @@ func (m *Mock) TestData() objx.Map {
|
||||||
Setting expectations
|
Setting expectations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Test sets the test struct variable of the mock object
|
// Test sets the [TestingT] on which errors will be reported, otherwise errors
|
||||||
|
// will cause a panic.
|
||||||
|
// Test should not be called on an object that is going to be used in a
|
||||||
|
// goroutine other than the one running the test function.
|
||||||
func (m *Mock) Test(t TestingT) {
|
func (m *Mock) Test(t TestingT) {
|
||||||
m.mutex.Lock()
|
m.mutex.Lock()
|
||||||
defer m.mutex.Unlock()
|
defer m.mutex.Unlock()
|
||||||
|
|
@ -494,7 +504,7 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen
|
||||||
// expected call found, but it has already been called with repeatable times
|
// expected call found, but it has already been called with repeatable times
|
||||||
if call != nil {
|
if call != nil {
|
||||||
m.mutex.Unlock()
|
m.mutex.Unlock()
|
||||||
m.fail("\nassert: mock: The method has been called over %d times.\n\tEither do one more Mock.On(\"%s\").Return(...), or remove extra call.\n\tThis call was unexpected:\n\t\t%s\n\tat: %s", call.totalCalls, methodName, callString(methodName, arguments, true), assert.CallerInfo())
|
m.fail("\nassert: mock: The method has been called over %d times.\n\tEither do one more Mock.On(%#v).Return(...), or remove extra call.\n\tThis call was unexpected:\n\t\t%s\n\tat: %s", call.totalCalls, methodName, callString(methodName, arguments, true), assert.CallerInfo())
|
||||||
}
|
}
|
||||||
// we have to fail here - because we don't know what to do
|
// we have to fail here - because we don't know what to do
|
||||||
// as the return arguments. This is because:
|
// as the return arguments. This is because:
|
||||||
|
|
@ -514,7 +524,7 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen
|
||||||
assert.CallerInfo(),
|
assert.CallerInfo(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
m.fail("\nassert: mock: I don't know what to return because the method call was unexpected.\n\tEither do Mock.On(\"%s\").Return(...) first, or remove the %s() call.\n\tThis method was unexpected:\n\t\t%s\n\tat: %s", methodName, methodName, callString(methodName, arguments, true), assert.CallerInfo())
|
m.fail("\nassert: mock: I don't know what to return because the method call was unexpected.\n\tEither do Mock.On(%#v).Return(...) first, or remove the %s() call.\n\tThis method was unexpected:\n\t\t%s\n\tat: %s", methodName, methodName, callString(methodName, arguments, true), assert.CallerInfo())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -661,7 +671,7 @@ func (m *Mock) AssertNumberOfCalls(t TestingT, methodName string, expectedCalls
|
||||||
actualCalls++
|
actualCalls++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return assert.Equal(t, expectedCalls, actualCalls, fmt.Sprintf("Expected number of calls (%d) does not match the actual number of calls (%d).", expectedCalls, actualCalls))
|
return assert.Equal(t, expectedCalls, actualCalls, fmt.Sprintf("Expected number of calls (%d) of method %s does not match the actual number of calls (%d).", expectedCalls, methodName, actualCalls))
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssertCalled asserts that the method was called.
|
// AssertCalled asserts that the method was called.
|
||||||
|
|
@ -938,6 +948,8 @@ func (args Arguments) Is(objects ...interface{}) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type outputRenderer func() string
|
||||||
|
|
||||||
// Diff gets a string describing the differences between the arguments
|
// Diff gets a string describing the differences between the arguments
|
||||||
// and the specified objects.
|
// and the specified objects.
|
||||||
//
|
//
|
||||||
|
|
@ -945,7 +957,7 @@ func (args Arguments) Is(objects ...interface{}) bool {
|
||||||
func (args Arguments) Diff(objects []interface{}) (string, int) {
|
func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||||
// TODO: could return string as error and nil for No difference
|
// TODO: could return string as error and nil for No difference
|
||||||
|
|
||||||
output := "\n"
|
var outputBuilder strings.Builder
|
||||||
var differences int
|
var differences int
|
||||||
|
|
||||||
maxArgCount := len(args)
|
maxArgCount := len(args)
|
||||||
|
|
@ -953,24 +965,35 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||||
maxArgCount = len(objects)
|
maxArgCount = len(objects)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outputRenderers := []outputRenderer{}
|
||||||
|
|
||||||
for i := 0; i < maxArgCount; i++ {
|
for i := 0; i < maxArgCount; i++ {
|
||||||
|
i := i
|
||||||
var actual, expected interface{}
|
var actual, expected interface{}
|
||||||
var actualFmt, expectedFmt string
|
var actualFmt, expectedFmt func() string
|
||||||
|
|
||||||
if len(objects) <= i {
|
if len(objects) <= i {
|
||||||
actual = "(Missing)"
|
actual = "(Missing)"
|
||||||
actualFmt = "(Missing)"
|
actualFmt = func() string {
|
||||||
|
return "(Missing)"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
actual = objects[i]
|
actual = objects[i]
|
||||||
actualFmt = fmt.Sprintf("(%[1]T=%[1]v)", actual)
|
actualFmt = func() string {
|
||||||
|
return fmt.Sprintf("(%[1]T=%[1]v)", actual)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) <= i {
|
if len(args) <= i {
|
||||||
expected = "(Missing)"
|
expected = "(Missing)"
|
||||||
expectedFmt = "(Missing)"
|
expectedFmt = func() string {
|
||||||
|
return "(Missing)"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
expected = args[i]
|
expected = args[i]
|
||||||
expectedFmt = fmt.Sprintf("(%[1]T=%[1]v)", expected)
|
expectedFmt = func() string {
|
||||||
|
return fmt.Sprintf("(%[1]T=%[1]v)", expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if matcher, ok := expected.(argumentMatcher); ok {
|
if matcher, ok := expected.(argumentMatcher); ok {
|
||||||
|
|
@ -978,16 +1001,22 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||||
func() {
|
func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
actualFmt = fmt.Sprintf("panic in argument matcher: %v", r)
|
actualFmt = func() string {
|
||||||
|
return fmt.Sprintf("panic in argument matcher: %v", r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
matches = matcher.Matches(actual)
|
matches = matcher.Matches(actual)
|
||||||
}()
|
}()
|
||||||
if matches {
|
if matches {
|
||||||
output = fmt.Sprintf("%s\t%d: PASS: %s matched by %s\n", output, i, actualFmt, matcher)
|
outputRenderers = append(outputRenderers, func() string {
|
||||||
|
return fmt.Sprintf("\t%d: PASS: %s matched by %s\n", i, actualFmt(), matcher)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
differences++
|
differences++
|
||||||
output = fmt.Sprintf("%s\t%d: FAIL: %s not matched by %s\n", output, i, actualFmt, matcher)
|
outputRenderers = append(outputRenderers, func() string {
|
||||||
|
return fmt.Sprintf("\t%d: FAIL: %s not matched by %s\n", i, actualFmt(), matcher)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch expected := expected.(type) {
|
switch expected := expected.(type) {
|
||||||
|
|
@ -996,13 +1025,17 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||||
if reflect.TypeOf(actual).Name() != string(expected) && reflect.TypeOf(actual).String() != string(expected) {
|
if reflect.TypeOf(actual).Name() != string(expected) && reflect.TypeOf(actual).String() != string(expected) {
|
||||||
// not match
|
// not match
|
||||||
differences++
|
differences++
|
||||||
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected, reflect.TypeOf(actual).Name(), actualFmt)
|
outputRenderers = append(outputRenderers, func() string {
|
||||||
|
return fmt.Sprintf("\t%d: FAIL: type %s != type %s - %s\n", i, expected, reflect.TypeOf(actual).Name(), actualFmt())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
case *IsTypeArgument:
|
case *IsTypeArgument:
|
||||||
actualT := reflect.TypeOf(actual)
|
actualT := reflect.TypeOf(actual)
|
||||||
if actualT != expected.t {
|
if actualT != expected.t {
|
||||||
differences++
|
differences++
|
||||||
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected.t.Name(), actualT.Name(), actualFmt)
|
outputRenderers = append(outputRenderers, func() string {
|
||||||
|
return fmt.Sprintf("\t%d: FAIL: type %s != type %s - %s\n", i, expected.t.Name(), actualT.Name(), actualFmt())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
case *FunctionalOptionsArgument:
|
case *FunctionalOptionsArgument:
|
||||||
var name string
|
var name string
|
||||||
|
|
@ -1013,26 +1046,36 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||||
const tName = "[]interface{}"
|
const tName = "[]interface{}"
|
||||||
if name != reflect.TypeOf(actual).String() && len(expected.values) != 0 {
|
if name != reflect.TypeOf(actual).String() && len(expected.values) != 0 {
|
||||||
differences++
|
differences++
|
||||||
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, tName, reflect.TypeOf(actual).Name(), actualFmt)
|
outputRenderers = append(outputRenderers, func() string {
|
||||||
|
return fmt.Sprintf("\t%d: FAIL: type %s != type %s - %s\n", i, tName, reflect.TypeOf(actual).Name(), actualFmt())
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
if ef, af := assertOpts(expected.values, actual); ef == "" && af == "" {
|
if ef, af := assertOpts(expected.values, actual); ef == "" && af == "" {
|
||||||
// match
|
// match
|
||||||
output = fmt.Sprintf("%s\t%d: PASS: %s == %s\n", output, i, tName, tName)
|
outputRenderers = append(outputRenderers, func() string {
|
||||||
|
return fmt.Sprintf("\t%d: PASS: %s == %s\n", i, tName, tName)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// not match
|
// not match
|
||||||
differences++
|
differences++
|
||||||
output = fmt.Sprintf("%s\t%d: FAIL: %s != %s\n", output, i, af, ef)
|
outputRenderers = append(outputRenderers, func() string {
|
||||||
|
return fmt.Sprintf("\t%d: FAIL: %s != %s\n", i, af, ef)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) {
|
if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) {
|
||||||
// match
|
// match
|
||||||
output = fmt.Sprintf("%s\t%d: PASS: %s == %s\n", output, i, actualFmt, expectedFmt)
|
outputRenderers = append(outputRenderers, func() string {
|
||||||
|
return fmt.Sprintf("\t%d: PASS: %s == %s\n", i, actualFmt(), expectedFmt())
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// not match
|
// not match
|
||||||
differences++
|
differences++
|
||||||
output = fmt.Sprintf("%s\t%d: FAIL: %s != %s\n", output, i, actualFmt, expectedFmt)
|
outputRenderers = append(outputRenderers, func() string {
|
||||||
|
return fmt.Sprintf("\t%d: FAIL: %s != %s\n", i, actualFmt(), expectedFmt())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1043,7 +1086,12 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||||
return "No differences.", differences
|
return "No differences.", differences
|
||||||
}
|
}
|
||||||
|
|
||||||
return output, differences
|
outputBuilder.WriteString("\n")
|
||||||
|
for _, r := range outputRenderers {
|
||||||
|
outputBuilder.WriteString(r())
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputBuilder.String(), differences
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert compares the arguments with the specified objects and fails if
|
// Assert compares the arguments with the specified objects and fails if
|
||||||
|
|
|
||||||
2
vendor/github.com/stretchr/testify/require/doc.go
generated
vendored
2
vendor/github.com/stretchr/testify/require/doc.go
generated
vendored
|
|
@ -23,6 +23,8 @@
|
||||||
//
|
//
|
||||||
// The `require` package have same global functions as in the `assert` package,
|
// The `require` package have same global functions as in the `assert` package,
|
||||||
// but instead of returning a boolean result they call `t.FailNow()`.
|
// but instead of returning a boolean result they call `t.FailNow()`.
|
||||||
|
// A consequence of this is that it must be called from the goroutine running
|
||||||
|
// the test function, not from other goroutines created during the test.
|
||||||
//
|
//
|
||||||
// Every assertion function also takes an optional string message as the final argument,
|
// Every assertion function also takes an optional string message as the final argument,
|
||||||
// allowing custom error messages to be appended to the message the assertion method outputs.
|
// allowing custom error messages to be appended to the message the assertion method outputs.
|
||||||
|
|
|
||||||
104
vendor/github.com/stretchr/testify/require/require.go
generated
vendored
104
vendor/github.com/stretchr/testify/require/require.go
generated
vendored
|
|
@ -117,10 +117,19 @@ func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
// Empty asserts that the given value is "empty".
|
||||||
// a slice or a channel with len == 0.
|
//
|
||||||
|
// [Zero values] are "empty".
|
||||||
|
//
|
||||||
|
// Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
|
||||||
|
//
|
||||||
|
// Slices, maps and channels with zero length are "empty".
|
||||||
|
//
|
||||||
|
// Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
|
||||||
//
|
//
|
||||||
// require.Empty(t, obj)
|
// require.Empty(t, obj)
|
||||||
|
//
|
||||||
|
// [Zero values]: https://go.dev/ref/spec#The_zero_value
|
||||||
func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
|
func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -131,10 +140,19 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
// Emptyf asserts that the given value is "empty".
|
||||||
// a slice or a channel with len == 0.
|
//
|
||||||
|
// [Zero values] are "empty".
|
||||||
|
//
|
||||||
|
// Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
|
||||||
|
//
|
||||||
|
// Slices, maps and channels with zero length are "empty".
|
||||||
|
//
|
||||||
|
// Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
|
||||||
//
|
//
|
||||||
// require.Emptyf(t, obj, "error message %s", "formatted")
|
// require.Emptyf(t, obj, "error message %s", "formatted")
|
||||||
|
//
|
||||||
|
// [Zero values]: https://go.dev/ref/spec#The_zero_value
|
||||||
func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) {
|
func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -280,9 +298,7 @@ func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ar
|
||||||
// Error asserts that a function returned an error (i.e. not `nil`).
|
// Error asserts that a function returned an error (i.e. not `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if require.Error(t, err) {
|
// require.Error(t, err)
|
||||||
// require.Equal(t, expectedError, err)
|
|
||||||
// }
|
|
||||||
func Error(t TestingT, err error, msgAndArgs ...interface{}) {
|
func Error(t TestingT, err error, msgAndArgs ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -374,9 +390,7 @@ func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface
|
||||||
// Errorf asserts that a function returned an error (i.e. not `nil`).
|
// Errorf asserts that a function returned an error (i.e. not `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if require.Errorf(t, err, "error message %s", "formatted") {
|
// require.Errorf(t, err, "error message %s", "formatted")
|
||||||
// require.Equal(t, expectedErrorf, err)
|
|
||||||
// }
|
|
||||||
func Errorf(t TestingT, err error, msg string, args ...interface{}) {
|
func Errorf(t TestingT, err error, msg string, args ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1097,7 +1111,35 @@ func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interf
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNotType asserts that the specified objects are not of the same type.
|
||||||
|
//
|
||||||
|
// require.IsNotType(t, &NotMyStruct{}, &MyStruct{})
|
||||||
|
func IsNotType(t TestingT, theType interface{}, object interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
if assert.IsNotType(t, theType, object, msgAndArgs...) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotTypef asserts that the specified objects are not of the same type.
|
||||||
|
//
|
||||||
|
// require.IsNotTypef(t, &NotMyStruct{}, &MyStruct{}, "error message %s", "formatted")
|
||||||
|
func IsNotTypef(t TestingT, theType interface{}, object interface{}, msg string, args ...interface{}) {
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
if assert.IsNotTypef(t, theType, object, msg, args...) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
// IsType asserts that the specified objects are of the same type.
|
// IsType asserts that the specified objects are of the same type.
|
||||||
|
//
|
||||||
|
// require.IsType(t, &MyStruct{}, &MyStruct{})
|
||||||
func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
|
func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1109,6 +1151,8 @@ func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsTypef asserts that the specified objects are of the same type.
|
// IsTypef asserts that the specified objects are of the same type.
|
||||||
|
//
|
||||||
|
// require.IsTypef(t, &MyStruct{}, &MyStruct{}, "error message %s", "formatted")
|
||||||
func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) {
|
func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1469,8 +1513,7 @@ func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg str
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
// NotEmpty asserts that the specified object is NOT [Empty].
|
||||||
// a slice or a channel with len == 0.
|
|
||||||
//
|
//
|
||||||
// if require.NotEmpty(t, obj) {
|
// if require.NotEmpty(t, obj) {
|
||||||
// require.Equal(t, "two", obj[1])
|
// require.Equal(t, "two", obj[1])
|
||||||
|
|
@ -1485,8 +1528,7 @@ func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
// NotEmptyf asserts that the specified object is NOT [Empty].
|
||||||
// a slice or a channel with len == 0.
|
|
||||||
//
|
//
|
||||||
// if require.NotEmptyf(t, obj, "error message %s", "formatted") {
|
// if require.NotEmptyf(t, obj, "error message %s", "formatted") {
|
||||||
// require.Equal(t, "two", obj[1])
|
// require.Equal(t, "two", obj[1])
|
||||||
|
|
@ -1745,12 +1787,15 @@ func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string,
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotSubset asserts that the specified list(array, slice...) or map does NOT
|
// NotSubset asserts that the list (array, slice, or map) does NOT contain all
|
||||||
// contain all elements given in the specified subset list(array, slice...) or
|
// elements given in the subset (array, slice, or map).
|
||||||
// map.
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// require.NotSubset(t, [1, 3, 4], [1, 2])
|
// require.NotSubset(t, [1, 3, 4], [1, 2])
|
||||||
// require.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
|
// require.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
|
||||||
|
// require.NotSubset(t, [1, 3, 4], {1: "one", 2: "two"})
|
||||||
|
// require.NotSubset(t, {"x": 1, "y": 2}, ["z"])
|
||||||
func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
|
func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1761,12 +1806,15 @@ func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...i
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotSubsetf asserts that the specified list(array, slice...) or map does NOT
|
// NotSubsetf asserts that the list (array, slice, or map) does NOT contain all
|
||||||
// contain all elements given in the specified subset list(array, slice...) or
|
// elements given in the subset (array, slice, or map).
|
||||||
// map.
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// require.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted")
|
// require.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted")
|
||||||
// require.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
|
// require.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
|
||||||
|
// require.NotSubsetf(t, [1, 3, 4], {1: "one", 2: "two"}, "error message %s", "formatted")
|
||||||
|
// require.NotSubsetf(t, {"x": 1, "y": 2}, ["z"], "error message %s", "formatted")
|
||||||
func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
|
func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1971,11 +2019,15 @@ func Samef(t TestingT, expected interface{}, actual interface{}, msg string, arg
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subset asserts that the specified list(array, slice...) or map contains all
|
// Subset asserts that the list (array, slice, or map) contains all elements
|
||||||
// elements given in the specified subset list(array, slice...) or map.
|
// given in the subset (array, slice, or map).
|
||||||
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// require.Subset(t, [1, 2, 3], [1, 2])
|
// require.Subset(t, [1, 2, 3], [1, 2])
|
||||||
// require.Subset(t, {"x": 1, "y": 2}, {"x": 1})
|
// require.Subset(t, {"x": 1, "y": 2}, {"x": 1})
|
||||||
|
// require.Subset(t, [1, 2, 3], {1: "one", 2: "two"})
|
||||||
|
// require.Subset(t, {"x": 1, "y": 2}, ["x"])
|
||||||
func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
|
func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1986,11 +2038,15 @@ func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...inte
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subsetf asserts that the specified list(array, slice...) or map contains all
|
// Subsetf asserts that the list (array, slice, or map) contains all elements
|
||||||
// elements given in the specified subset list(array, slice...) or map.
|
// given in the subset (array, slice, or map).
|
||||||
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// require.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted")
|
// require.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted")
|
||||||
// require.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
|
// require.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
|
||||||
|
// require.Subsetf(t, [1, 2, 3], {1: "one", 2: "two"}, "error message %s", "formatted")
|
||||||
|
// require.Subsetf(t, {"x": 1, "y": 2}, ["x"], "error message %s", "formatted")
|
||||||
func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
|
func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
|
||||||
if h, ok := t.(tHelper); ok {
|
if h, ok := t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
|
||||||
98
vendor/github.com/stretchr/testify/require/require_forward.go
generated
vendored
98
vendor/github.com/stretchr/testify/require/require_forward.go
generated
vendored
|
|
@ -93,10 +93,19 @@ func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg st
|
||||||
ElementsMatchf(a.t, listA, listB, msg, args...)
|
ElementsMatchf(a.t, listA, listB, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
// Empty asserts that the given value is "empty".
|
||||||
// a slice or a channel with len == 0.
|
//
|
||||||
|
// [Zero values] are "empty".
|
||||||
|
//
|
||||||
|
// Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
|
||||||
|
//
|
||||||
|
// Slices, maps and channels with zero length are "empty".
|
||||||
|
//
|
||||||
|
// Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
|
||||||
//
|
//
|
||||||
// a.Empty(obj)
|
// a.Empty(obj)
|
||||||
|
//
|
||||||
|
// [Zero values]: https://go.dev/ref/spec#The_zero_value
|
||||||
func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) {
|
func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -104,10 +113,19 @@ func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) {
|
||||||
Empty(a.t, object, msgAndArgs...)
|
Empty(a.t, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
// Emptyf asserts that the given value is "empty".
|
||||||
// a slice or a channel with len == 0.
|
//
|
||||||
|
// [Zero values] are "empty".
|
||||||
|
//
|
||||||
|
// Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
|
||||||
|
//
|
||||||
|
// Slices, maps and channels with zero length are "empty".
|
||||||
|
//
|
||||||
|
// Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
|
||||||
//
|
//
|
||||||
// a.Emptyf(obj, "error message %s", "formatted")
|
// a.Emptyf(obj, "error message %s", "formatted")
|
||||||
|
//
|
||||||
|
// [Zero values]: https://go.dev/ref/spec#The_zero_value
|
||||||
func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) {
|
func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -226,9 +244,7 @@ func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string
|
||||||
// Error asserts that a function returned an error (i.e. not `nil`).
|
// Error asserts that a function returned an error (i.e. not `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if a.Error(err) {
|
// a.Error(err)
|
||||||
// assert.Equal(t, expectedError, err)
|
|
||||||
// }
|
|
||||||
func (a *Assertions) Error(err error, msgAndArgs ...interface{}) {
|
func (a *Assertions) Error(err error, msgAndArgs ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -299,9 +315,7 @@ func (a *Assertions) ErrorIsf(err error, target error, msg string, args ...inter
|
||||||
// Errorf asserts that a function returned an error (i.e. not `nil`).
|
// Errorf asserts that a function returned an error (i.e. not `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if a.Errorf(err, "error message %s", "formatted") {
|
// a.Errorf(err, "error message %s", "formatted")
|
||||||
// assert.Equal(t, expectedErrorf, err)
|
|
||||||
// }
|
|
||||||
func (a *Assertions) Errorf(err error, msg string, args ...interface{}) {
|
func (a *Assertions) Errorf(err error, msg string, args ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -869,7 +883,29 @@ func (a *Assertions) IsNonIncreasingf(object interface{}, msg string, args ...in
|
||||||
IsNonIncreasingf(a.t, object, msg, args...)
|
IsNonIncreasingf(a.t, object, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNotType asserts that the specified objects are not of the same type.
|
||||||
|
//
|
||||||
|
// a.IsNotType(&NotMyStruct{}, &MyStruct{})
|
||||||
|
func (a *Assertions) IsNotType(theType interface{}, object interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if h, ok := a.t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
IsNotType(a.t, theType, object, msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotTypef asserts that the specified objects are not of the same type.
|
||||||
|
//
|
||||||
|
// a.IsNotTypef(&NotMyStruct{}, &MyStruct{}, "error message %s", "formatted")
|
||||||
|
func (a *Assertions) IsNotTypef(theType interface{}, object interface{}, msg string, args ...interface{}) {
|
||||||
|
if h, ok := a.t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
IsNotTypef(a.t, theType, object, msg, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// IsType asserts that the specified objects are of the same type.
|
// IsType asserts that the specified objects are of the same type.
|
||||||
|
//
|
||||||
|
// a.IsType(&MyStruct{}, &MyStruct{})
|
||||||
func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
|
func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -878,6 +914,8 @@ func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAnd
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsTypef asserts that the specified objects are of the same type.
|
// IsTypef asserts that the specified objects are of the same type.
|
||||||
|
//
|
||||||
|
// a.IsTypef(&MyStruct{}, &MyStruct{}, "error message %s", "formatted")
|
||||||
func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) {
|
func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1163,8 +1201,7 @@ func (a *Assertions) NotElementsMatchf(listA interface{}, listB interface{}, msg
|
||||||
NotElementsMatchf(a.t, listA, listB, msg, args...)
|
NotElementsMatchf(a.t, listA, listB, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
// NotEmpty asserts that the specified object is NOT [Empty].
|
||||||
// a slice or a channel with len == 0.
|
|
||||||
//
|
//
|
||||||
// if a.NotEmpty(obj) {
|
// if a.NotEmpty(obj) {
|
||||||
// assert.Equal(t, "two", obj[1])
|
// assert.Equal(t, "two", obj[1])
|
||||||
|
|
@ -1176,8 +1213,7 @@ func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) {
|
||||||
NotEmpty(a.t, object, msgAndArgs...)
|
NotEmpty(a.t, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
// NotEmptyf asserts that the specified object is NOT [Empty].
|
||||||
// a slice or a channel with len == 0.
|
|
||||||
//
|
//
|
||||||
// if a.NotEmptyf(obj, "error message %s", "formatted") {
|
// if a.NotEmptyf(obj, "error message %s", "formatted") {
|
||||||
// assert.Equal(t, "two", obj[1])
|
// assert.Equal(t, "two", obj[1])
|
||||||
|
|
@ -1379,12 +1415,15 @@ func (a *Assertions) NotSamef(expected interface{}, actual interface{}, msg stri
|
||||||
NotSamef(a.t, expected, actual, msg, args...)
|
NotSamef(a.t, expected, actual, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotSubset asserts that the specified list(array, slice...) or map does NOT
|
// NotSubset asserts that the list (array, slice, or map) does NOT contain all
|
||||||
// contain all elements given in the specified subset list(array, slice...) or
|
// elements given in the subset (array, slice, or map).
|
||||||
// map.
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// a.NotSubset([1, 3, 4], [1, 2])
|
// a.NotSubset([1, 3, 4], [1, 2])
|
||||||
// a.NotSubset({"x": 1, "y": 2}, {"z": 3})
|
// a.NotSubset({"x": 1, "y": 2}, {"z": 3})
|
||||||
|
// a.NotSubset([1, 3, 4], {1: "one", 2: "two"})
|
||||||
|
// a.NotSubset({"x": 1, "y": 2}, ["z"])
|
||||||
func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) {
|
func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1392,12 +1431,15 @@ func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs
|
||||||
NotSubset(a.t, list, subset, msgAndArgs...)
|
NotSubset(a.t, list, subset, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotSubsetf asserts that the specified list(array, slice...) or map does NOT
|
// NotSubsetf asserts that the list (array, slice, or map) does NOT contain all
|
||||||
// contain all elements given in the specified subset list(array, slice...) or
|
// elements given in the subset (array, slice, or map).
|
||||||
// map.
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// a.NotSubsetf([1, 3, 4], [1, 2], "error message %s", "formatted")
|
// a.NotSubsetf([1, 3, 4], [1, 2], "error message %s", "formatted")
|
||||||
// a.NotSubsetf({"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
|
// a.NotSubsetf({"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
|
||||||
|
// a.NotSubsetf([1, 3, 4], {1: "one", 2: "two"}, "error message %s", "formatted")
|
||||||
|
// a.NotSubsetf({"x": 1, "y": 2}, ["z"], "error message %s", "formatted")
|
||||||
func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) {
|
func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1557,11 +1599,15 @@ func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string,
|
||||||
Samef(a.t, expected, actual, msg, args...)
|
Samef(a.t, expected, actual, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subset asserts that the specified list(array, slice...) or map contains all
|
// Subset asserts that the list (array, slice, or map) contains all elements
|
||||||
// elements given in the specified subset list(array, slice...) or map.
|
// given in the subset (array, slice, or map).
|
||||||
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// a.Subset([1, 2, 3], [1, 2])
|
// a.Subset([1, 2, 3], [1, 2])
|
||||||
// a.Subset({"x": 1, "y": 2}, {"x": 1})
|
// a.Subset({"x": 1, "y": 2}, {"x": 1})
|
||||||
|
// a.Subset([1, 2, 3], {1: "one", 2: "two"})
|
||||||
|
// a.Subset({"x": 1, "y": 2}, ["x"])
|
||||||
func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) {
|
func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
@ -1569,11 +1615,15 @@ func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...
|
||||||
Subset(a.t, list, subset, msgAndArgs...)
|
Subset(a.t, list, subset, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subsetf asserts that the specified list(array, slice...) or map contains all
|
// Subsetf asserts that the list (array, slice, or map) contains all elements
|
||||||
// elements given in the specified subset list(array, slice...) or map.
|
// given in the subset (array, slice, or map).
|
||||||
|
// Map elements are key-value pairs unless compared with an array or slice where
|
||||||
|
// only the map key is evaluated.
|
||||||
//
|
//
|
||||||
// a.Subsetf([1, 2, 3], [1, 2], "error message %s", "formatted")
|
// a.Subsetf([1, 2, 3], [1, 2], "error message %s", "formatted")
|
||||||
// a.Subsetf({"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
|
// a.Subsetf({"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
|
||||||
|
// a.Subsetf([1, 2, 3], {1: "one", 2: "two"}, "error message %s", "formatted")
|
||||||
|
// a.Subsetf({"x": 1, "y": 2}, ["x"], "error message %s", "formatted")
|
||||||
func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) {
|
func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) {
|
||||||
if h, ok := a.t.(tHelper); ok {
|
if h, ok := a.t.(tHelper); ok {
|
||||||
h.Helper()
|
h.Helper()
|
||||||
|
|
|
||||||
16
vendor/github.com/stretchr/testify/suite/stats.go
generated
vendored
16
vendor/github.com/stretchr/testify/suite/stats.go
generated
vendored
|
|
@ -16,26 +16,30 @@ type TestInformation struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSuiteInformation() *SuiteInformation {
|
func newSuiteInformation() *SuiteInformation {
|
||||||
testStats := make(map[string]*TestInformation)
|
|
||||||
|
|
||||||
return &SuiteInformation{
|
return &SuiteInformation{
|
||||||
TestStats: testStats,
|
TestStats: make(map[string]*TestInformation),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SuiteInformation) start(testName string) {
|
func (s *SuiteInformation) start(testName string) {
|
||||||
|
if s == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
s.TestStats[testName] = &TestInformation{
|
s.TestStats[testName] = &TestInformation{
|
||||||
TestName: testName,
|
TestName: testName,
|
||||||
Start: time.Now(),
|
Start: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SuiteInformation) end(testName string, passed bool) {
|
func (s *SuiteInformation) end(testName string, passed bool) {
|
||||||
|
if s == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
s.TestStats[testName].End = time.Now()
|
s.TestStats[testName].End = time.Now()
|
||||||
s.TestStats[testName].Passed = passed
|
s.TestStats[testName].Passed = passed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SuiteInformation) Passed() bool {
|
func (s *SuiteInformation) Passed() bool {
|
||||||
for _, stats := range s.TestStats {
|
for _, stats := range s.TestStats {
|
||||||
if !stats.Passed {
|
if !stats.Passed {
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
94
vendor/github.com/stretchr/testify/suite/suite.go
generated
vendored
94
vendor/github.com/stretchr/testify/suite/suite.go
generated
vendored
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -15,7 +16,6 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var allTestsFilter = func(_, _ string) (bool, error) { return true, nil }
|
|
||||||
var matchMethod = flag.String("testify.m", "", "regular expression to select tests of the testify suite to run")
|
var matchMethod = flag.String("testify.m", "", "regular expression to select tests of the testify suite to run")
|
||||||
|
|
||||||
// Suite is a basic testing suite with methods for storing and
|
// Suite is a basic testing suite with methods for storing and
|
||||||
|
|
@ -116,6 +116,11 @@ func (suite *Suite) Run(name string, subtest func()) bool {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type test = struct {
|
||||||
|
name string
|
||||||
|
run func(t *testing.T)
|
||||||
|
}
|
||||||
|
|
||||||
// Run takes a testing suite and runs all of the tests attached
|
// Run takes a testing suite and runs all of the tests attached
|
||||||
// to it.
|
// to it.
|
||||||
func Run(t *testing.T, suite TestingSuite) {
|
func Run(t *testing.T, suite TestingSuite) {
|
||||||
|
|
@ -124,45 +129,39 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
suite.SetT(t)
|
suite.SetT(t)
|
||||||
suite.SetS(suite)
|
suite.SetS(suite)
|
||||||
|
|
||||||
var suiteSetupDone bool
|
|
||||||
|
|
||||||
var stats *SuiteInformation
|
var stats *SuiteInformation
|
||||||
if _, ok := suite.(WithStats); ok {
|
if _, ok := suite.(WithStats); ok {
|
||||||
stats = newSuiteInformation()
|
stats = newSuiteInformation()
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []testing.InternalTest{}
|
var tests []test
|
||||||
methodFinder := reflect.TypeOf(suite)
|
methodFinder := reflect.TypeOf(suite)
|
||||||
suiteName := methodFinder.Elem().Name()
|
suiteName := methodFinder.Elem().Name()
|
||||||
|
|
||||||
for i := 0; i < methodFinder.NumMethod(); i++ {
|
var matchMethodRE *regexp.Regexp
|
||||||
method := methodFinder.Method(i)
|
if *matchMethod != "" {
|
||||||
|
var err error
|
||||||
ok, err := methodFilter(method.Name)
|
matchMethodRE, err = regexp.Compile(*matchMethod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err)
|
fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !ok {
|
for i := 0; i < methodFinder.NumMethod(); i++ {
|
||||||
|
method := methodFinder.Method(i)
|
||||||
|
|
||||||
|
if !strings.HasPrefix(method.Name, "Test") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Apply -testify.m filter
|
||||||
|
if matchMethodRE != nil && !matchMethodRE.MatchString(method.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !suiteSetupDone {
|
test := test{
|
||||||
if stats != nil {
|
name: method.Name,
|
||||||
stats.Start = time.Now()
|
run: func(t *testing.T) {
|
||||||
}
|
|
||||||
|
|
||||||
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
|
|
||||||
setupAllSuite.SetupSuite()
|
|
||||||
}
|
|
||||||
|
|
||||||
suiteSetupDone = true
|
|
||||||
}
|
|
||||||
|
|
||||||
test := testing.InternalTest{
|
|
||||||
Name: method.Name,
|
|
||||||
F: func(t *testing.T) {
|
|
||||||
parentT := suite.T()
|
parentT := suite.T()
|
||||||
suite.SetT(t)
|
suite.SetT(t)
|
||||||
defer recoverAndFailOnPanic(t)
|
defer recoverAndFailOnPanic(t)
|
||||||
|
|
@ -171,10 +170,7 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
|
|
||||||
r := recover()
|
r := recover()
|
||||||
|
|
||||||
if stats != nil {
|
stats.end(method.Name, !t.Failed() && r == nil)
|
||||||
passed := !t.Failed() && r == nil
|
|
||||||
stats.end(method.Name, passed)
|
|
||||||
}
|
|
||||||
|
|
||||||
if afterTestSuite, ok := suite.(AfterTest); ok {
|
if afterTestSuite, ok := suite.(AfterTest); ok {
|
||||||
afterTestSuite.AfterTest(suiteName, method.Name)
|
afterTestSuite.AfterTest(suiteName, method.Name)
|
||||||
|
|
@ -195,16 +191,26 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
|
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if stats != nil {
|
|
||||||
stats.start(method.Name)
|
stats.start(method.Name)
|
||||||
}
|
|
||||||
|
|
||||||
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tests = append(tests, test)
|
tests = append(tests, test)
|
||||||
}
|
}
|
||||||
if suiteSetupDone {
|
|
||||||
|
if len(tests) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if stats != nil {
|
||||||
|
stats.Start = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
|
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
|
||||||
|
setupAllSuite.SetupSuite()
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
||||||
tearDownAllSuite.TearDownSuite()
|
tearDownAllSuite.TearDownSuite()
|
||||||
|
|
@ -215,39 +221,17 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
suiteWithStats.HandleStats(suiteName, stats)
|
suiteWithStats.HandleStats(suiteName, stats)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
|
||||||
|
|
||||||
runTests(t, tests)
|
runTests(t, tests)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filtering method according to set regular expression
|
func runTests(t *testing.T, tests []test) {
|
||||||
// specified command-line argument -m
|
|
||||||
func methodFilter(name string) (bool, error) {
|
|
||||||
if ok, _ := regexp.MatchString("^Test", name); !ok {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return regexp.MatchString(*matchMethod, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func runTests(t testing.TB, tests []testing.InternalTest) {
|
|
||||||
if len(tests) == 0 {
|
if len(tests) == 0 {
|
||||||
t.Log("warning: no tests to run")
|
t.Log("warning: no tests to run")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
r, ok := t.(runner)
|
|
||||||
if !ok { // backwards compatibility with Go 1.6 and below
|
|
||||||
if !testing.RunTests(allTestsFilter, tests) {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
r.Run(test.Name, test.F)
|
t.Run(test.name, test.run)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type runner interface {
|
|
||||||
Run(name string, f func(t *testing.T)) bool
|
|
||||||
}
|
|
||||||
|
|
|
||||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
|
@ -216,7 +216,7 @@ github.com/spf13/pflag
|
||||||
# github.com/stretchr/objx v0.5.2
|
# github.com/stretchr/objx v0.5.2
|
||||||
## explicit; go 1.20
|
## explicit; go 1.20
|
||||||
github.com/stretchr/objx
|
github.com/stretchr/objx
|
||||||
# github.com/stretchr/testify v1.10.0
|
# github.com/stretchr/testify v1.11.0
|
||||||
## explicit; go 1.17
|
## explicit; go 1.17
|
||||||
github.com/stretchr/testify/assert
|
github.com/stretchr/testify/assert
|
||||||
github.com/stretchr/testify/assert/yaml
|
github.com/stretchr/testify/assert/yaml
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue