FFFF Show exit code and both output streams when a CLI error assertion fails by ahus1 · Pull Request #54796 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Draft
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.test.junit.main.LaunchResult;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionTimeoutException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -72,15 +73,21 @@ public int exitCode() {
}

private static void awaitOutput(String reason, String message, Supplier<String> supplier, CLIResult result) {
if (result.exitCode() == -1) {
Awaitility.await(reason)
.atMost(5, TimeUnit.SECONDS)
.untilAsserted(() -> assertThat(reason, supplier.get(), containsString(message)));
} else {
assertThat(reason, supplier.get(), containsString(message));
try {
if (result.exitCode() == -1) {
Awaitility.await(reason)
.atMost(5, TimeUnit.SECONDS)
.untilAsserted(() -> assertThat(reason, supplier.get(), containsString(message)));
} else {
assertThat(reason, supplier.get(), containsString(message));
}
} catch (AssertionError | ConditionTimeoutException e) {
// the other stream and the exit code show if the output ended up elsewhere or the process ended early
throw new AssertionError("%s (exit code: %s, stdout: %s, stderr: %s)".formatted(e.getMessage(),
result.exitCode(), result.getOutputStream(), result.getErrorStream()), e);
}
}

private static void noOutput(String reason, String message, Supplier<String> supplier, CLIResult result, boolean allowRunning) {
if (!allowRunning && result.exitCode() == -1) {
throw new AssertionError("This assertion should not be used against a server with manual stop mode");
Expand Down
Loading
0