Skip to content

Commit a2dc5ea

Browse files
committed
test(integration): dump compose logs on failure for diagnostics
Last CI run got past the port-collision but OPA never became ready and all we saw was "context deadline exceeded" with no idea why. Add a helper that dumps `docker compose logs --tail 200` and `docker compose ps -a` when the test fails or when waitForOPA times out, so the next failure surfaces the actual reason in the GHA log.
1 parent b7514fb commit a2dc5ea

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

cmd/opa-nats/main_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,22 @@ func TestIntegration(t *testing.T) {
5757

5858
// Clean up any existing containers (also runs at end via t.Cleanup).
5959
composeArgs := []string{"compose", "-f", "docker-compose.yaml", "-f", overrideFile}
60+
dumpComposeLogs := func(reason string) {
61+
t.Logf("Dumping docker compose logs (%s):", reason)
62+
logsArgs := append([]string{}, composeArgs...)
63+
logsArgs = append(logsArgs, "logs", "--no-color", "--tail", "200")
64+
out, _ := exec.Command("docker", logsArgs...).CombinedOutput()
65+
t.Logf("--- BEGIN compose logs ---\n%s\n--- END compose logs ---", string(out))
66+
psArgs := append([]string{}, composeArgs...)
67+
psArgs = append(psArgs, "ps", "-a")
68+
ps, _ := exec.Command("docker", psArgs...).CombinedOutput()
69+
t.Logf("--- compose ps ---\n%s", string(ps))
70+
}
6071
t.Cleanup(func() {
6172
_ = os.Chdir(examplesDir)
73+
if t.Failed() {
74+
dumpComposeLogs("test failed")
75+
}
6276
downArgs := append([]string{}, composeArgs...)
6377
downArgs = append(downArgs, "down", "-v", "--remove-orphans")
6478
exec.Command("docker", downArgs...).Run()
@@ -79,7 +93,10 @@ func TestIntegration(t *testing.T) {
7993

8094
// Wait for OPA to be ready
8195
t.Log("Waiting for OPA to be ready...")
82-
require.NoError(t, waitForOPA(ctx, "http://localhost:8181"))
96+
if err := waitForOPA(ctx, "http://localhost:8181"); err != nil {
97+
dumpComposeLogs("OPA never became ready")
98+
t.Fatalf("OPA never became ready: %v", err)
99+
}
83100

84101
// Test OPA health endpoint
85102
t.Run("OPA Health Check", func(t *testing.T) {

0 commit comments

Comments
 (0)