Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run integration tests after logging refactor #4

Closed
Closed
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
41 changes: 18 additions & 23 deletions integration/dockertestutil/logs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package dockertestutil

import (
"bytes"
"bufio"
"context"
"fmt"
"io"
"log"
"os"
Expand Down Expand Up @@ -46,35 +47,29 @@ func SaveLog(
return "", "", err
}

// Wouldn't it be simpler to
// open and wrap the destination files in a
// bufio.Writer, and pass those in docker.LogsOptions?
var stdout bytes.Buffer
var stderr bytes.Buffer

err = WriteLog(pool, resource, &stdout, &stderr)
if err != nil {
return "", "", err
}

log.Printf("Saving logs for %s to %s\n", resource.Container.Name, basePath)

stdoutPath := path.Join(basePath, resource.Container.Name+".stdout.log")
err = os.WriteFile(
stdoutPath,
stdout.Bytes(),
filePerm,
)
stdout, err := os.OpenFile(stdoutPath, os.O_CREATE|os.O_WRONLY, filePerm)
if err != nil {
return "", "", err
return "", "", fmt.Errorf("failed to open stdout for writing: %w", err)
}
defer stdout.Close()

stderrPath := path.Join(basePath, resource.Container.Name+".stderr.log")
err = os.WriteFile(
stderrPath,
stderr.Bytes(),
filePerm,
)
stderr, err := os.OpenFile(stderrPath, os.O_CREATE|os.O_WRONLY, filePerm)
if err != nil {
return "", "", fmt.Errorf("failed to open stderr for writing: %w", err)
}
defer stderr.Close()

bufOut := bufio.NewWriter(stdout)
bufErr := bufio.NewWriter(stderr)

defer bufOut.Flush()
defer bufErr.Flush()

err = WriteLog(pool, resource, bufOut, bufErr)
if err != nil {
return "", "", err
}
Expand Down
Loading