From 95b4a9e25003e9e645a856f8dc61329ae2cae343 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 6 Jun 2024 10:19:28 +0200 Subject: [PATCH] osbuild-worker-executor: make test output silent again Do not use the global logger but pass instead the locally created logger. This means the test output is silent again. Sadly using the global logger is difficult because it is a global resource so replacing it in tests means all tests (that are potentially run in parallel) will write to it which makes testing specific log output hard. --- cmd/osbuild-worker-executor/handler_build.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/osbuild-worker-executor/handler_build.go b/cmd/osbuild-worker-executor/handler_build.go index a790ae523..096876ab5 100644 --- a/cmd/osbuild-worker-executor/handler_build.go +++ b/cmd/osbuild-worker-executor/handler_build.go @@ -39,7 +39,7 @@ func (wf *writeFlusher) Write(p []byte) (n int, err error) { return n, err } -func runOsbuild(buildDir string, control *controlJSON, output io.Writer) (string, error) { +func runOsbuild(logger *logrus.Logger, buildDir string, control *controlJSON, output io.Writer) (string, error) { flusher, ok := output.(http.Flusher) if !ok { return "", fmt.Errorf("cannot stream the output") @@ -92,11 +92,11 @@ func runOsbuild(buildDir string, control *controlJSON, output io.Writer) (string out, err := cmd.CombinedOutput() if err != nil { err = fmt.Errorf("cannot tar output directory: %w, output:\n%s", err, out) - logrus.Errorf(err.Error()) + logger.Errorf(err.Error()) _, _ = mw.Write([]byte(err.Error())) return "", err } - logrus.Infof("tar output:\n%s", out) + logger.Infof("tar output:\n%s", out) return outputDir, nil } @@ -286,7 +286,7 @@ func handleBuild(logger *logrus.Logger, config *Config) http.Handler { // run osbuild and stream the output to the client buildResult := newBuildResult(config) - _, err = runOsbuild(buildDir, control, w) + _, err = runOsbuild(logger, buildDir, control, w) if werr := buildResult.Mark(err); werr != nil { logger.Errorf("cannot write result file %v", werr) }