mirror of https://github.com/stretchr/testify.git
fix name regression
parent
22d3bd5def
commit
822223ec34
20
mock/mock.go
20
mock/mock.go
|
@ -1211,6 +1211,20 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) {
|
|||
return
|
||||
}
|
||||
|
||||
var expectedNames []string
|
||||
for i := 0; i < expectedOpts.Len(); i++ {
|
||||
expectedNames = append(expectedNames, funcName(expectedOpts.Index(i).Interface()))
|
||||
}
|
||||
var actualNames []string
|
||||
for i := 0; i < actualOpts.Len(); i++ {
|
||||
actualNames = append(actualNames, funcName(actualOpts.Index(i).Interface()))
|
||||
}
|
||||
if !assert.ObjectsAreEqual(expectedNames, actualNames) {
|
||||
expectedFmt = fmt.Sprintf("%v", expectedNames)
|
||||
actualFmt = fmt.Sprintf("%v", actualNames)
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < expectedOpts.Len(); i++ {
|
||||
expectedOpt := expectedOpts.Index(i).Interface()
|
||||
actualOpt := actualOpts.Index(i).Interface()
|
||||
|
@ -1232,9 +1246,9 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) {
|
|||
reflect.ValueOf(actualOpt).Call(actualValues)
|
||||
|
||||
for i := 0; i < ot.NumIn(); i++ {
|
||||
if !assert.ObjectsAreEqual(expectedValues[i].Interface(), actualValues[i].Interface()) {
|
||||
expectedFmt = fmt.Sprintf("%s %+v", funcName(expectedOpts.Index(i).Interface()), expectedValues[i].Interface())
|
||||
actualFmt = fmt.Sprintf("%s %+v", funcName(actualOpts.Index(i).Interface()), actualValues[i].Interface())
|
||||
if expectedArg, actualArg := expectedValues[i].Interface(), actualValues[i].Interface(); !assert.ObjectsAreEqual(expectedArg, actualArg) {
|
||||
expectedFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], expectedArg, expectedArg)
|
||||
actualFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], actualArg, actualArg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,13 @@ func OpStr(s string) OptionFn {
|
|||
o.str = s
|
||||
}
|
||||
}
|
||||
|
||||
func OpBytes(b []byte) OptionFn {
|
||||
return func(m *options) {
|
||||
m.str = string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *TestExampleImplementation) TheExampleMethodFunctionalOptions(x string, opts ...OptionFn) error {
|
||||
args := i.Called(x, opts)
|
||||
return args.Error(0)
|
||||
|
@ -1509,7 +1516,7 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func Test_Mock_AssertExpectationsFunctionalOptionsTypeIndirectly(t *testing.T) {
|
||||
func Test_Mock_AssertExpectationsFunctionalOptionsType_Indirectly(t *testing.T) {
|
||||
|
||||
var mockedService = new(TestExampleImplementation)
|
||||
|
||||
|
@ -1543,17 +1550,31 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff(t *testing.T) {
|
||||
func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff_Name(t *testing.T) {
|
||||
|
||||
var mockedService = new(TestExampleImplementation)
|
||||
|
||||
mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpNum(1))).Return(nil).Once()
|
||||
mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpStr("this"))).Return(nil).Once()
|
||||
|
||||
tt := new(testing.T)
|
||||
assert.False(t, mockedService.AssertExpectations(tt))
|
||||
|
||||
assert.Panics(t, func() {
|
||||
mockedService.TheExampleMethodFunctionalOptions("test", OpStr("1"))
|
||||
mockedService.TheExampleMethodFunctionalOptions("test", OpBytes([]byte("this")))
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff_Arg(t *testing.T) {
|
||||
|
||||
var mockedService = new(TestExampleImplementation)
|
||||
|
||||
mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpStr("this"))).Return(nil).Once()
|
||||
|
||||
tt := new(testing.T)
|
||||
assert.False(t, mockedService.AssertExpectations(tt))
|
||||
|
||||
assert.Panics(t, func() {
|
||||
mockedService.TheExampleMethodFunctionalOptions("test", OpStr("that"))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue