github.com/operator-framework/operator-lifecycle-manager@v0.30.0/test/e2e/util/gomega/catalogsource_matchers.go (about) 1 package gomega 2 3 import ( 4 "fmt" 5 6 "github.com/onsi/gomega/matchers" 7 "github.com/onsi/gomega/types" 8 "github.com/operator-framework/api/pkg/operators/v1alpha1" 9 "github.com/operator-framework/operator-lifecycle-manager/test/e2e/util" 10 "google.golang.org/grpc/connectivity" 11 ) 12 13 func HaveGrpcConnectionWithLastConnectionState(state connectivity.State) types.GomegaMatcher { 14 return &CatalogSourceGrpcConnectionLastConnectionStateMatcher{ 15 EqualMatcher: &matchers.EqualMatcher{ 16 Expected: state.String(), 17 }, 18 } 19 } 20 21 type CatalogSourceGrpcConnectionLastConnectionStateMatcher struct { 22 *matchers.EqualMatcher 23 } 24 25 func (s *CatalogSourceGrpcConnectionLastConnectionStateMatcher) FailureMessage(actual interface{}) (message string) { 26 return fmt.Sprintf("expected catalog source status.grpcConnectionState.lastObservedState to be '%s'\n%s\n", s.Expected, util.ObjectToPrettyJsonString(actual)) 27 } 28 29 func (s *CatalogSourceGrpcConnectionLastConnectionStateMatcher) NegatedFailureMessage(actual interface{}) (message string) { 30 return fmt.Sprintf("expected catalog status.grpcConnectionState.lastObservedState to NOT be '%s':\n%s\n ", s.Expected, util.ObjectToPrettyJsonString(actual)) 31 } 32 33 func (s *CatalogSourceGrpcConnectionLastConnectionStateMatcher) Match(actual interface{}) (bool, error) { 34 switch actual := actual.(type) { 35 case *v1alpha1.CatalogSource: 36 if actual.Status.GRPCConnectionState == nil { 37 return false, fmt.Errorf("catalog source does not have a grpc connection state") 38 } 39 util.Logf("expecting catalog source last connection state '%s' to be '%s'", actual.Status.GRPCConnectionState.LastObservedState, s.Expected) 40 return s.EqualMatcher.Match(actual.Status.GRPCConnectionState.LastObservedState) 41 default: 42 return false, fmt.Errorf("actual %v is not a subscription", actual) 43 } 44 }