open-cluster-management.io/governance-policy-propagator@v0.13.0/test/utils/semanticMatcher.go (about) 1 // Copyright (c) 2020 Red Hat, Inc. 2 // Copyright Contributors to the Open Cluster Management project 3 4 package utils 5 6 import ( 7 "fmt" 8 9 "github.com/onsi/gomega/types" 10 "k8s.io/apimachinery/pkg/api/equality" 11 ) 12 13 func SemanticEqual(expected interface{}) types.GomegaMatcher { 14 return &semanticMatcher{ 15 expected: expected, 16 } 17 } 18 19 type semanticMatcher struct { 20 expected interface{} 21 } 22 23 func (matcher *semanticMatcher) Match(actual interface{}) (success bool, err error) { 24 return equality.Semantic.DeepEqual(actual, matcher.expected), nil 25 } 26 27 func (matcher *semanticMatcher) FailureMessage(actual interface{}) (message string) { 28 return fmt.Sprintf("Expected\n\t%#v\nto equal\n\t%#v", actual, matcher.expected) 29 } 30 31 func (matcher *semanticMatcher) NegatedFailureMessage(actual interface{}) (message string) { 32 return fmt.Sprintf("Expected\n\t%#v\nnot to equal\n\t%#v", actual, matcher.expected) 33 }