This commit imports the repository https://github.com/mvo5/oaas without keeping the history. The history is largely unimportant and can be looked up in https://github.com/mvo5/oaas/commits/main if needed.
45 lines
809 B
Go
45 lines
809 B
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
logrusTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
var (
|
|
Run = run
|
|
|
|
HandleIncludedSources = handleIncludedSources
|
|
)
|
|
|
|
func MockLogger() (hook *logrusTest.Hook, restore func()) {
|
|
saved := logrusNew
|
|
logger, hook := logrusTest.NewNullLogger()
|
|
logrusNew = func() *logrus.Logger {
|
|
return logger
|
|
}
|
|
logger.SetLevel(logrus.DebugLevel)
|
|
|
|
return hook, func() {
|
|
logrusNew = saved
|
|
}
|
|
}
|
|
|
|
func MockOsbuildBinary(t *testing.T, new string) (restore func()) {
|
|
t.Helper()
|
|
|
|
saved := osbuildBinary
|
|
|
|
tmpdir := t.TempDir()
|
|
osbuildBinary = filepath.Join(tmpdir, "fake-osbuild")
|
|
if err := ioutil.WriteFile(osbuildBinary, []byte(new), 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
return func() {
|
|
osbuildBinary = saved
|
|
}
|
|
}
|