...

Source file src/github.com/openshift/custom-resource-status/testlib/matcher.go

Documentation: github.com/openshift/custom-resource-status/testlib

     1  package testlib
     2  
     3  import (
     4  	"fmt"
     5  
     6  	gomegatypes "github.com/onsi/gomega/types"
     7  	conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
     8  )
     9  
    10  // RepresentCondition - returns a GomegaMatcher useful for comparing conditions
    11  func RepresentCondition(expected conditionsv1.Condition) gomegatypes.GomegaMatcher {
    12  	return &representConditionMatcher{
    13  		expected: expected,
    14  	}
    15  }
    16  
    17  type representConditionMatcher struct {
    18  	expected conditionsv1.Condition
    19  }
    20  
    21  // Match - compares two conditions
    22  // two conditions are the same if they have the same type, status, reason, and message
    23  func (matcher *representConditionMatcher) Match(actual interface{}) (success bool, err error) {
    24  	actualCondition, ok := actual.(conditionsv1.Condition)
    25  	if !ok {
    26  		return false, fmt.Errorf("RepresentConditionMatcher expects a Condition")
    27  	}
    28  
    29  	if matcher.expected.Type != actualCondition.Type {
    30  		return false, nil
    31  	}
    32  	if matcher.expected.Status != actualCondition.Status {
    33  		return false, nil
    34  	}
    35  	if matcher.expected.Reason != actualCondition.Reason {
    36  		return false, nil
    37  	}
    38  	if matcher.expected.Message != actualCondition.Message {
    39  		return false, nil
    40  	}
    41  	return true, nil
    42  }
    43  
    44  func (matcher *representConditionMatcher) FailureMessage(actual interface{}) (message string) {
    45  	return fmt.Sprintf("Expected\n\t%#v\nto match the condition\n\t%#v", actual, matcher.expected)
    46  }
    47  
    48  func (matcher *representConditionMatcher) NegatedFailureMessage(actual interface{}) (message string) {
    49  	return fmt.Sprintf("Expected\n\t%#v\nnot to match the condition\n\t%#v", actual, matcher.expected)
    50  }
    51  

View as plain text