diff --git a/pkg/condition/condition.go b/pkg/condition/condition.go index 289336e1..8a7a5f60 100644 --- a/pkg/condition/condition.go +++ b/pkg/condition/condition.go @@ -173,12 +173,16 @@ func containsConditions(conditions []toolchainv1alpha1.Condition, contains toolc return false } -// ContainsCondition returns true if the specified list of conditions contains the specified condition and the statuses of the conditions match. +// ContainsCondition returns true if the specified list of conditions contains the specified condition and the statuses +// of the conditions match. This function does not compare the values of the message property. // LastTransitionTime is ignored. func ContainsCondition(conditions []toolchainv1alpha1.Condition, contains toolchainv1alpha1.Condition) bool { return containsConditions(conditions, contains, true) } +// ContainsConditionWithMessage returns true if the specified list of conditions contains the specified condition and the +// statuses and the message property of the conditions match. +// LastTransitionTime is ignored. func ContainsConditionWithMessage(conditions []toolchainv1alpha1.Condition, contains toolchainv1alpha1.Condition) bool { return containsConditions(conditions, contains, false) } diff --git a/pkg/condition/condition_blackbox_test.go b/pkg/condition/condition_blackbox_test.go index 868e70de..f6cc2ce9 100644 --- a/pkg/condition/condition_blackbox_test.go +++ b/pkg/condition/condition_blackbox_test.go @@ -544,6 +544,38 @@ func reverseStatus(status apiv1.ConditionStatus) apiv1.ConditionStatus { } } +func TestContainsConditionWithMessage(t *testing.T) { + conditions1 := []toolchainv1alpha1.Condition{ + { + Type: toolchainv1alpha1.UserSignupComplete, + Status: apiv1.ConditionTrue, + Reason: toolchainv1alpha1.UserSignupApprovedAutomaticallyReason, + Message: "foo", + }, + { + Type: toolchainv1alpha1.UserSignupUserDeactivatingNotificationCreated, + Status: apiv1.ConditionTrue, + Reason: toolchainv1alpha1.UserSignupUserDeactivatingReason, + Message: "bar", + }, + } + require.True(t, condition.ContainsConditionWithMessage(conditions1, + toolchainv1alpha1.Condition{ + Type: toolchainv1alpha1.UserSignupUserDeactivatingNotificationCreated, + Status: apiv1.ConditionTrue, + Reason: toolchainv1alpha1.UserSignupUserDeactivatingReason, + Message: "bar", + })) + + require.False(t, condition.ContainsConditionWithMessage(conditions1, + toolchainv1alpha1.Condition{ + Type: toolchainv1alpha1.UserSignupUserDeactivatingNotificationCreated, + Status: apiv1.ConditionTrue, + Reason: toolchainv1alpha1.UserSignupUserDeactivatingReason, + Message: "foo", + })) +} + func TestConditionsMatch(t *testing.T) { conditions1 := []toolchainv1alpha1.Condition{ {