Improving the error messages in the Operator Test

Closes #31598

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Alexander Schwartz 2024-07-25 09:37:01 +02:00 committed by Michal Hajas
parent 6d404b86c9
commit 28a27c9148

View file

@ -54,15 +54,23 @@ public final class CRAssert {
public static ObjectAssert<KeycloakStatusCondition> assertKeycloakStatusCondition(KeycloakStatus kcStatus, String condition, Boolean status, String containedMessage, Long observedGeneration) {
KeycloakStatusCondition statusCondition = kcStatus.findCondition(condition).orElseThrow();
assertThat(statusCondition.getStatus()).isEqualTo(status);
assertThat(statusCondition.getStatus())
.withFailMessage(() -> "found status " + statusCondition + " and expected status " + status)
.isEqualTo(status);
if (containedMessage != null) {
assertThat(statusCondition.getMessage()).contains(containedMessage);
assertThat(statusCondition.getMessage())
.withFailMessage(() -> "found status " + statusCondition + " and expected it to contain " + containedMessage)
.contains(containedMessage);
}
if (observedGeneration != null) {
assertThat(statusCondition.getObservedGeneration()).isEqualTo(observedGeneration);
assertThat(statusCondition.getObservedGeneration())
.withFailMessage(() -> "found status " + statusCondition + " and expected it to contain an observed generation of " + observedGeneration)
.isEqualTo(observedGeneration);
}
if (status != null) {
assertThat(statusCondition.getLastTransitionTime()).isNotNull();
assertThat(statusCondition.getLastTransitionTime())
.withFailMessage(() -> "found status " + statusCondition + " and expected the last transition time to not be null")
.isNotNull();
}
return assertThat(statusCondition);
}