From 59b9685078bf164db0452cd64981981ae2fcf659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Irving=20Mondrag=C3=B3n?= Date: Tue, 31 Mar 2026 10:10:00 +0200 Subject: [PATCH] test(e2e): capture container logs on test failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Irving Mondragón --- tests/e2e/suite_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/e2e/suite_test.go b/tests/e2e/suite_test.go index e7cb9a66..5e6110b0 100644 --- a/tests/e2e/suite_test.go +++ b/tests/e2e/suite_test.go @@ -15,6 +15,7 @@ package urunce2etesting import ( + "errors" "fmt" "os" "testing" @@ -77,6 +78,25 @@ func skipMissingVolumes(tc containerTestArgs) { } } +// captureContainerLogs attaches container logs to the Ginkgo report on failure. +func captureContainerLogs(tool testTool) { + if !CurrentSpecReport().Failed() { + return + } + logs, err := tool.logContainer() + if errors.Is(err, errToolDoesNotSupport) { + GinkgoLogr.Info("Container log capture not supported by " + tool.Name()) + return + } + if err != nil { + GinkgoLogr.Error(err, "Failed to capture container logs") + return + } + if logs != "" { + AddReportEntry("container-logs", logs) + } +} + // runDetachedTest runs a container in detached mode: create, start, and // verify via TestFunc. func runDetachedTest(tool testTool, tc containerTestArgs) { @@ -87,6 +107,7 @@ func runDetachedTest(tool testTool, tc containerTestArgs) { DeferCleanup(func() { if tool.getContainerID() != "" { + captureContainerLogs(tool) By("Stopping container") if err := tool.stopContainer(); err != nil { GinkgoLogr.Error(err, "Failed to stop container")