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.
30 lines
468 B
Go
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
|
|
}
|
|
}
|