Skip to content

Commit

Permalink
move matcher to file
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBollag committed May 24, 2023
1 parent e471219 commit efe52c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
37 changes: 37 additions & 0 deletions src/operator/controllers/intents_reconcilers/client_matcher.go
Original file line number Diff line number Diff line change
@@ -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}
}
31 changes: 0 additions & 31 deletions src/operator/controllers/intents_reconcilers/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit efe52c6

Please sign in to comment.