@@ -20,13 +20,32 @@ type conditionMatcher[T comparable] struct {
2020 expected * ConditionImpl [T ]
2121}
2222
23+ func (c * conditionMatcher [T ]) GomegaString () string {
24+ if c == nil || c .expected == nil {
25+ return "<nil>"
26+ }
27+ return c .expected .String ()
28+ }
29+
2330var _ types.GomegaMatcher = & conditionMatcher [bool ]{}
2431
2532// Match implements types.GomegaMatcher.
26- func (c * conditionMatcher [T ]) Match (actualRaw interface {}) (success bool , err error ) {
27- actual , ok := actualRaw .(conditions.Condition [T ])
28- if ! ok {
29- return false , fmt .Errorf ("expected actual to be of type Condition[%s], got %T" , reflect .TypeFor [T ]().Name (), actualRaw )
33+ func (c * conditionMatcher [T ]) Match (actualRaw any ) (success bool , err error ) {
34+ actual , converted := actualRaw .(conditions.Condition [T ])
35+ if ! converted {
36+ // actualRaw doesn't implement conditions.Condition[T], check if a pointer to it does
37+ ptrValue := reflect .New (reflect .TypeOf (actualRaw ))
38+ reflect .Indirect (ptrValue ).Set (reflect .ValueOf (actualRaw ))
39+ actual , converted = ptrValue .Interface ().(conditions.Condition [T ])
40+ }
41+ if ! converted {
42+ return false , fmt .Errorf ("expected actual (or &actual) to be of type Condition[%s], got %T" , reflect .TypeFor [T ]().Name (), actualRaw )
43+ }
44+ if actual == nil && c .expected == nil {
45+ return true , nil
46+ }
47+ if actual == nil || c .expected == nil {
48+ return false , nil
3049 }
3150 if c .expected .HasType () && c .expected .GetType () != actual .GetType () {
3251 return false , nil
@@ -86,6 +105,39 @@ type ConditionImpl[T comparable] struct {
86105 lastTransitionTime * time.Time
87106}
88107
108+ func (c * ConditionImpl [T ]) String () string {
109+ if c == nil {
110+ return "<nil>"
111+ }
112+ var status , conType , reason , message , lastTransitionTime string
113+ if c .status == nil {
114+ status = "<arbitrary>"
115+ } else {
116+ status = fmt .Sprintf ("%v" , * c .status )
117+ }
118+ if c .conType == nil {
119+ conType = "<arbitrary>"
120+ } else {
121+ conType = * c .conType
122+ }
123+ if c .reason == nil {
124+ reason = "<arbitrary>"
125+ } else {
126+ reason = * c .reason
127+ }
128+ if c .message == nil {
129+ message = "<arbitrary>"
130+ } else {
131+ message = * c .message
132+ }
133+ if c .lastTransitionTime == nil {
134+ lastTransitionTime = "<arbitrary>"
135+ } else {
136+ lastTransitionTime = c .lastTransitionTime .Format (time .RFC3339 )
137+ }
138+ return fmt .Sprintf ("Condition[%s]{\n \t Type: %q,\n \t Status: %s,\n \t Reason: %q,\n \t Message: %q,\n \t LastTransitionTime: %v,\n }" , reflect .TypeFor [T ]().Name (), conType , status , reason , message , lastTransitionTime )
139+ }
140+
89141var _ conditions.Condition [bool ] = & ConditionImpl [bool ]{}
90142
91143func (c * ConditionImpl [T ]) GetLastTransitionTime () time.Time {
0 commit comments