-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e471219
commit efe52c6
Showing
2 changed files
with
37 additions
and
31 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/operator/controllers/intents_reconcilers/client_matcher.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters