build(deps): 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:
+71
-23
@@ -208,9 +208,16 @@ func (c *Call) On(methodName string, arguments ...interface{}) *Call {
|
||||
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 {
|
||||
var unlockOnce sync.Once
|
||||
|
||||
@@ -331,7 +338,10 @@ func (m *Mock) TestData() objx.Map {
|
||||
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) {
|
||||
m.mutex.Lock()
|
||||
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
|
||||
if call != nil {
|
||||
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
|
||||
// as the return arguments. This is because:
|
||||
@@ -514,7 +524,7 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen
|
||||
assert.CallerInfo(),
|
||||
)
|
||||
} 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++
|
||||
}
|
||||
}
|
||||
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.
|
||||
@@ -938,6 +948,8 @@ func (args Arguments) Is(objects ...interface{}) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type outputRenderer func() string
|
||||
|
||||
// Diff gets a string describing the differences between the arguments
|
||||
// and the specified objects.
|
||||
//
|
||||
@@ -945,7 +957,7 @@ func (args Arguments) Is(objects ...interface{}) bool {
|
||||
func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||
// TODO: could return string as error and nil for No difference
|
||||
|
||||
output := "\n"
|
||||
var outputBuilder strings.Builder
|
||||
var differences int
|
||||
|
||||
maxArgCount := len(args)
|
||||
@@ -953,24 +965,35 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||
maxArgCount = len(objects)
|
||||
}
|
||||
|
||||
outputRenderers := []outputRenderer{}
|
||||
|
||||
for i := 0; i < maxArgCount; i++ {
|
||||
i := i
|
||||
var actual, expected interface{}
|
||||
var actualFmt, expectedFmt string
|
||||
var actualFmt, expectedFmt func() string
|
||||
|
||||
if len(objects) <= i {
|
||||
actual = "(Missing)"
|
||||
actualFmt = "(Missing)"
|
||||
actualFmt = func() string {
|
||||
return "(Missing)"
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
expected = "(Missing)"
|
||||
expectedFmt = "(Missing)"
|
||||
expectedFmt = func() string {
|
||||
return "(Missing)"
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
@@ -978,16 +1001,22 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||
func() {
|
||||
defer func() {
|
||||
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)
|
||||
}()
|
||||
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 {
|
||||
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 {
|
||||
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) {
|
||||
// not match
|
||||
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:
|
||||
actualT := reflect.TypeOf(actual)
|
||||
if actualT != expected.t {
|
||||
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:
|
||||
var name string
|
||||
@@ -1013,26 +1046,36 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
|
||||
const tName = "[]interface{}"
|
||||
if name != reflect.TypeOf(actual).String() && len(expected.values) != 0 {
|
||||
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 {
|
||||
if ef, af := assertOpts(expected.values, actual); ef == "" && af == "" {
|
||||
// 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 {
|
||||
// not match
|
||||
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:
|
||||
if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) {
|
||||
// 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 {
|
||||
// not match
|
||||
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 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
|
||||
|
||||
Reference in New Issue
Block a user