Skip to content

Commit

Permalink
comments, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbryzak committed May 9, 2024
1 parent 5f159ea commit 783e16f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
32 changes: 32 additions & 0 deletions pkg/condition/condition_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down

0 comments on commit 783e16f

Please sign in to comment.