Skip to content
Open
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
21 changes: 21 additions & 0 deletions tests/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package urunce2etesting

import (
"errors"
"fmt"
"os"
"testing"
Expand Down Expand Up @@ -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) {
Expand All @@ -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")
Expand Down
Loading