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.
This commit is contained in:
Michael Vogt 2024-06-06 10:19:28 +02:00 committed by Sanne Raymaekers
parent a634868793
commit 95b4a9e250

View file

@ -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)
}