diff --git a/src/operator/controllers/intents_reconcilers/client_matcher.go b/src/operator/controllers/intents_reconcilers/client_matcher.go new file mode 100644 index 000000000..93979c39c --- /dev/null +++ b/src/operator/controllers/intents_reconcilers/client_matcher.go @@ -0,0 +1,37 @@ +package intents_reconcilers + +import ( + "github.com/golang/mock/gomock" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +type ClientPatch struct { + client.Patch +} + +func (p ClientPatch) Matches(x interface{}) bool { + patch := x.(client.Patch) + actualData, err := patch.Data(nil) + if err != nil { + return false + } + + expectedData, err := p.Data(nil) + if err != nil { + return false + } + + return string(actualData) == string(expectedData) && patch.Type() == p.Type() +} + +func (p ClientPatch) String() string { + data, err := p.Data(nil) + if err != nil { + return "format error" + } + return string(data) +} + +func MatchPatch(patch client.Patch) gomock.Matcher { + return ClientPatch{patch} +} diff --git a/src/operator/controllers/intents_reconcilers/pods_test.go b/src/operator/controllers/intents_reconcilers/pods_test.go index 8c9ff07c2..87c3c653e 100644 --- a/src/operator/controllers/intents_reconcilers/pods_test.go +++ b/src/operator/controllers/intents_reconcilers/pods_test.go @@ -21,37 +21,6 @@ const ( testNamespace = "test-namespace" ) -type ClientPatch struct { - client.Patch -} - -func (p ClientPatch) Matches(x interface{}) bool { - patch := x.(client.Patch) - actualData, err := patch.Data(nil) - if err != nil { - return false - } - - expectedData, err := p.Data(nil) - if err != nil { - return false - } - - return string(actualData) == string(expectedData) && patch.Type() == p.Type() -} - -func (p ClientPatch) String() string { - data, err := p.Data(nil) - if err != nil { - return "format error" - } - return string(data) -} - -func MatchPatch(patch client.Patch) gomock.Matcher { - return ClientPatch{patch} -} - type PodLabelReconcilerTestSuite struct { suite.Suite Reconciler *PodLabelReconciler