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

Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions quarkus/tests/junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit-internal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 @@ -73,15 +74,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) {
assertThat(reason, supplier.get(), not(containsString(message)));
}
Expand Down
4 changes: 4 additions & 0 deletions test-framework/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
Expand Down
Loading
0