Skip to content

Commit

Permalink
Cleanups from review
Browse files Browse the repository at this point in the history
Co-authored-by: Giles Hutton <[email protected]>
  • Loading branch information
Molter73 and Stringy committed Oct 1, 2024
1 parent a5966ce commit 76d367d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
4 changes: 4 additions & 0 deletions integration-tests/pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type ContainerLogs struct {
Stderr string
}

func (c *ContainerLogs) Empty() bool {
return *c == (ContainerLogs{})
}

// Will return Stderr if it is not empty, otherwise it returns Stdout.
// Useful for accessing the logs for collector and container-stats
// that use a single stream.
Expand Down
60 changes: 28 additions & 32 deletions integration-tests/pkg/executor/executor_docker_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,49 +199,45 @@ func (c *dockerAPIExecutor) CaptureLogs(testName, containerName string) (string,
return "", log.Error("logs error (%v) for container %s\n", err, containerName)
}

if logs == (ContainerLogs{}) {
// Nothing to log
return "", nil
type logFile = struct {
name string
content string
}

if logs.Stderr == "" || logs.Stdout == "" {
var logFiles []logFile
if logs.Empty() {
// Nothing to log, still we create an empty file for awareness
logFiles = []logFile{{
name: fmt.Sprintf("%s.log", containerName),
}}
} else if logs.Stderr == "" || logs.Stdout == "" {
// We only have stdout OR stderr to log
logName := fmt.Sprintf("%s.log", containerName)
logFile, err := common.PrepareLog(testName, logName)
if err != nil {
return "", err
}
defer logFile.Close()

l := logs.GetSingleLog()
_, err = logFile.WriteString(l)
return l, nil
}

// We need to log both stdout and stderr, do so on separate files
for _, log := range []struct {
name string
content string
}{
{
name: fmt.Sprintf("%s-stdout.log", containerName),
content: logs.Stdout,
},
{
logFiles = []logFile{{
name: fmt.Sprintf("%s.log", containerName),
content: logs.GetSingleLog(),
}}
} else {
// We need to log both stdout and stderr, do so on separate files
logFiles = []logFile{{
name: fmt.Sprintf("%s-stderr.log", containerName),
content: logs.Stderr,
},
} {
logFile, err := common.PrepareLog(testName, log.name)
}, {
name: fmt.Sprintf("%s-stdout.log", containerName),
content: logs.Stdout,
}}
}

for _, lf := range logFiles {
file, err := common.PrepareLog(testName, lf.name)
if err != nil {
return "", err
}
defer logFile.Close()
defer file.Close()

_, err = logFile.WriteString(log.content)
file.WriteString(lf.content)
}

return logs.Stderr, nil
return logFiles[0].content, nil
}

func (d *dockerAPIExecutor) KillContainer(containerID string) (string, error) {
Expand Down

0 comments on commit 76d367d

Please sign in to comment.