You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The changes introduced to support testing of functional options (#1023) are broken with indirect calls.
When the service which exposes the method that supports functional options is injected into another function and invoked, the mock assertions are broken.
The following test and mocks should be supported.
diff --git a/mock/mock_test.go b/mock/mock_test.go
index 60cf5d0..1c7ca47 100644
--- a/mock/mock_test.go+++ b/mock/mock_test.go@@ -20,6 +20,7 @@ import (
// ExampleInterface represents an example interface.
type ExampleInterface interface {
TheExampleMethod(a, b, c int) (int, error)
+ TheExampleMethodFunctionalOptions(x string, opts ...OptionFn) error
}
// TestExampleImplementation is a test implementation of ExampleInterface
@@ -1455,6 +1456,27 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType(t *testing.T) {
}
+func Test_Mock_AssertExpectationsFunctionalOptionsType_indirect(t *testing.T) {++ indirectFunctionalOptions := func(ei ExampleInterface) {+ ei.TheExampleMethodFunctionalOptions("testing", OpStr("test"), OpNum(1))+ }++ var mockedService = new(TestExampleImplementation)++ mockedService.On("TheExampleMethodFunctionalOptions", "testing", FunctionalOptions(OpStr("test"), OpNum(1))).Return(nil).Once()++ tt := new(testing.T)+ assert.False(t, mockedService.AssertExpectations(tt))++ // make the call now+ indirectFunctionalOptions(mockedService)++ // now assert expectations+ assert.True(t, mockedService.AssertExpectations(tt))++}+
func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) {
var mockedService = new(TestExampleImplementation)
but instead results in the following error:
mock: Unexpected Method Call
-----------------------------
TheExampleMethodFunctionalOptions(string,[]mock.OptionFn)
0: "testing"
1: []mock.OptionFn{(mock.OptionFn)(0x11a8020), (mock.OptionFn)(0x11a8000)}
The closest call I have is:
TheExampleMethodFunctionalOptions(string,*mock.FunctionalOptionsArgument)
0: "testing"
1: []mock.OptionFn{(mock.OptionFn)(0x11a0980), (mock.OptionFn)(0x11a0960)}
Diff: 0: PASS: (string=testing) == (string=testing)
1: FAIL: [mock.Test_Mock_AssertExpectationsFunctionalOptionsType_indirect.func1 mock.Test_Mock_AssertExpectationsFunctionalOptionsType_indirect.func1] != [mock.Test_Mock_AssertExpectationsFunctionalOptionsType_indirect mock.Test_Mock_AssertExpectationsFunctionalOptionsType_indirect]
The culprit seems to be the funcName call which is used in assertOpts returning unexpected values.
The text was updated successfully, but these errors were encountered:
Sad to see this never quite make it - I actually decided not to use functional options on a really suitable place for it the other day because of it. Is there any chance we could get #1381 going again?
The changes introduced to support testing of functional options (#1023) are broken with indirect calls.
When the service which exposes the method that supports functional options is injected into another function and invoked, the mock assertions are broken.
The following test and mocks should be supported.
but instead results in the following error:
The culprit seems to be the
funcName
call which is used inassertOpts
returning unexpected values.The text was updated successfully, but these errors were encountered: