Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ConditionsMatch function #397

Closed
wants to merge 9 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,32 @@
con, found := FindConditionByType(conditions, conditionType)
return found && con.Reason == reason
}

// ConditionsMatch checks whether the specified conditions match and return true if they do
func ConditionsMatch(first, second []toolchainv1alpha1.Condition) bool {
if len(first) != len(second) {
return false

Check warning on line 153 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L151-L153

Added lines #L151 - L153 were not covered by tests
}
for _, c := range first {
if !ContainsCondition(second, c) {
return false

Check warning on line 157 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L155-L157

Added lines #L155 - L157 were not covered by tests
}
}
for _, c := range second {
sbryzak marked this conversation as resolved.
Show resolved Hide resolved
if !ContainsCondition(first, c) {
return false

Check warning on line 162 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L160-L162

Added lines #L160 - L162 were not covered by tests
}
}
return true

Check warning on line 165 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L165

Added line #L165 was not covered by tests
}

// ContainsCondition returns true if the specified list of conditions contains the specified condition and the statuses of the conditions match.
// LastTransitionTime is ignored.
func ContainsCondition(conditions []toolchainv1alpha1.Condition, contains toolchainv1alpha1.Condition) bool {
for _, c := range conditions {
sbryzak marked this conversation as resolved.
Show resolved Hide resolved
if c.Type == contains.Type {
return contains.Status == c.Status && contains.Reason == c.Reason && contains.Message == c.Message

Check warning on line 173 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L170-L173

Added lines #L170 - L173 were not covered by tests
}
}
return false

Check warning on line 176 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L176

Added line #L176 was not covered by tests
}
Loading