Skip to content

Commit

Permalink
Change pod labels test to mock (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBollag committed May 28, 2023
1 parent 0828724 commit e296bb4
Show file tree
Hide file tree
Showing 4 changed files with 753 additions and 244 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}
}
3 changes: 3 additions & 0 deletions src/operator/controllers/intents_reconcilers/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package intents_reconcilers

//go:generate go run github.com/golang/mock/mockgen@v1.6.0 -destination=./mocks/mock_k8s_client.go -package=intentsreconcilersmocks sigs.k8s.io/controller-runtime/pkg/client Client
228 changes: 228 additions & 0 deletions src/operator/controllers/intents_reconcilers/mocks/mock_k8s_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e296bb4

Please sign in to comment.