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
With sigs.k8s.io/controller-runtime < v0.8.3 this test is working perfectly fine.
$ go test -mod=vendor -timeout 30s -run ^TestUtils$ github.com/ialidzhikov/example/pkg/utils
ok github.com/ialidzhikov/example/pkg/utils 0.787s
#1406 (also cherry-picked into release-0.8 branch) introduces a field of type func (createPatch ) in the mergeFromPatch struct. This breaks the naive gomock expectations. The reason is that the mergeFromPatch struct has now a function attribute (createPatch), and as gomock is using reflect.DeepEqual under the hood, the comparison now fails:
I have a hard time understanding what exactly go mock is doing here and why. Why is it looking at the private properties of the patch implementation rather than at its exported methods and the result of calling them?
None of our api compatibility testing checks compatibility of unexported types. If there is any expectation around compatibility of those, it needs to be agreed upon, formalized and verified in CI.
I can already tell you though that I am not a fan doing any of that. The very reason for exporting some things and not exporting others is to convey the message if a compatibility promise is given or not.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
After #1406, the client.Patch implementations are no longer gomock-friendly.
So we have unit tests that use gomock. Let's have the following example to get a better understanding.
pkg/utils.go
pkg/utils_test.go
Note:
MockClient
is a mock generated with gomockWith sigs.k8s.io/controller-runtime < v0.8.3 this test is working perfectly fine.
#1406 (also cherry-picked into release-0.8 branch) introduces a field of type func (
createPatch
) in themergeFromPatch
struct. This breaks the naive gomock expectations. The reason is that themergeFromPatch
struct has now a function attribute (createPatch
), and as gomock is usingreflect.DeepEqual
under the hood, the comparison now fails:Example of such failure with
sigs.k8s.io/[email protected]
:The text was updated successfully, but these errors were encountered: