mirror of https://github.com/stretchr/testify.git
fix: compare functional option names for indirect calls
Closes Functional Options testing broken for indirect calls #1380pull/1626/head
parent
7efaf15f33
commit
9c174eb41c
|
@ -1260,5 +1260,12 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) {
|
||||||
|
|
||||||
func funcName(opt interface{}) string {
|
func funcName(opt interface{}) string {
|
||||||
n := runtime.FuncForPC(reflect.ValueOf(opt).Pointer()).Name()
|
n := runtime.FuncForPC(reflect.ValueOf(opt).Pointer()).Name()
|
||||||
return strings.TrimSuffix(path.Base(n), path.Ext(n))
|
trimmed := strings.TrimSuffix(path.Base(n), path.Ext(n))
|
||||||
|
splitted := strings.Split(trimmed, ".")
|
||||||
|
|
||||||
|
if len(splitted) == 0 {
|
||||||
|
return trimmed
|
||||||
|
}
|
||||||
|
|
||||||
|
return splitted[len(splitted)-1]
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,10 @@ func (i *TestExampleImplementation) TheExampleMethodFunctionalOptions(x string,
|
||||||
return args.Error(0)
|
return args.Error(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TheExampleMethodFunctionalOptionsIndirect(i *TestExampleImplementation) {
|
||||||
|
i.TheExampleMethodFunctionalOptions("test", OpNum(1), OpStr("foo"))
|
||||||
|
}
|
||||||
|
|
||||||
//go:noinline
|
//go:noinline
|
||||||
func (i *TestExampleImplementation) TheExampleMethod2(yesorno bool) {
|
func (i *TestExampleImplementation) TheExampleMethod2(yesorno bool) {
|
||||||
i.Called(yesorno)
|
i.Called(yesorno)
|
||||||
|
@ -1505,6 +1509,23 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_Mock_AssertExpectationsFunctionalOptionsTypeIndirectly(t *testing.T) {
|
||||||
|
|
||||||
|
var mockedService = new(TestExampleImplementation)
|
||||||
|
|
||||||
|
mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpNum(1), OpStr("foo"))).Return(nil).Once()
|
||||||
|
|
||||||
|
tt := new(testing.T)
|
||||||
|
assert.False(t, mockedService.AssertExpectations(tt))
|
||||||
|
|
||||||
|
// make the call now
|
||||||
|
TheExampleMethodFunctionalOptionsIndirect(mockedService)
|
||||||
|
|
||||||
|
// now assert expectations
|
||||||
|
assert.True(t, mockedService.AssertExpectations(tt))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) {
|
func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) {
|
||||||
|
|
||||||
var mockedService = new(TestExampleImplementation)
|
var mockedService = new(TestExampleImplementation)
|
||||||
|
@ -1522,6 +1543,20 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff(t *testing.T) {
|
||||||
|
|
||||||
|
var mockedService = new(TestExampleImplementation)
|
||||||
|
|
||||||
|
mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpNum(1))).Return(nil).Once()
|
||||||
|
|
||||||
|
tt := new(testing.T)
|
||||||
|
assert.False(t, mockedService.AssertExpectations(tt))
|
||||||
|
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
mockedService.TheExampleMethodFunctionalOptions("test", OpStr("1"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func Test_Mock_AssertExpectations_With_Repeatability(t *testing.T) {
|
func Test_Mock_AssertExpectations_With_Repeatability(t *testing.T) {
|
||||||
|
|
||||||
var mockedService = new(TestExampleImplementation)
|
var mockedService = new(TestExampleImplementation)
|
||||||
|
|
Loading…
Reference in New Issue