From 711e6f6a6e7e8d71689f3ca208e66ce5168a7fc6 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/e2e/suite_test.go b/tests/e2e/suite_test.go index e7cb9a66..03d7db82 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,22 @@ func skipMissingVolumes(tc containerTestArgs) { } } +// captureContainerLogs attaches container logs to the Ginkgo report on failure. +func captureContainerLogs(tool testTool) { + 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 +104,9 @@ func runDetachedTest(tool testTool, tc containerTestArgs) { DeferCleanup(func() { if tool.getContainerID() != "" { + if CurrentSpecReport().Failed() { + captureContainerLogs(tool) + } By("Stopping container") if err := tool.stopContainer(); err != nil { GinkgoLogr.Error(err, "Failed to stop container")