debian-forge-composer/cmd/osbuild-worker-executor/export_test.go
Michael Vogt 8ebefbdbc9 main: rework the way the mock logger is passed
Pass the mock logger directly to `run()` instead of mocking
`logrus.New`. Doing the later leads to a data race when multiple
parallel tests modify the (global) `var logrusNew logrus.New`.

Thanks to Tomas Hozza for reporting.
2024-06-06 21:14:31 +02:00

30 lines
468 B
Go

package main
import (
"os"
"path/filepath"
"testing"
)
var (
Run = run
HandleIncludedSources = handleIncludedSources
)
func MockOsbuildBinary(t *testing.T, new string) (restore func()) {
t.Helper()
saved := osbuildBinary
tmpdir := t.TempDir()
osbuildBinary = filepath.Join(tmpdir, "fake-osbuild")
/* #nosec G306 */
if err := os.WriteFile(osbuildBinary, []byte(new), 0755); err != nil {
t.Fatal(err)
}
return func() {
osbuildBinary = saved
}
}