diff --git a/pkg/osbuild/export_test.go b/pkg/osbuild/export_test.go index 8376cc17fa..67960103ee 100644 --- a/pkg/osbuild/export_test.go +++ b/pkg/osbuild/export_test.go @@ -3,3 +3,11 @@ package osbuild type ( StatusJSON = statusJSON ) + +func MockOsbuildCmd(s string) (restore func()) { + saved := osbuildCmd + osbuildCmd = s + return func() { + osbuildCmd = saved + } +} diff --git a/pkg/osbuild/osbuild-exec.go b/pkg/osbuild/osbuild-exec.go index 83a7702c91..5d3f6bd419 100644 --- a/pkg/osbuild/osbuild-exec.go +++ b/pkg/osbuild/osbuild-exec.go @@ -24,7 +24,7 @@ const ( MonitorLog = "LogMonitor" ) -var OSBuildCmd = "osbuild" +var osbuildCmd = "osbuild" type OSBuildOptions struct { StoreDir string @@ -49,7 +49,7 @@ func NewOSBuildCmd(manifest []byte, exports, checkpoints []string, optsPtr *OSBu // nolint: gosec cmd := exec.Command( - OSBuildCmd, + osbuildCmd, "--store", opts.StoreDir, "--output-directory", opts.OutputDir, fmt.Sprintf("--cache-max-size=%v", cacheMaxSize), @@ -156,7 +156,7 @@ func CheckMinimumOSBuildVersion() error { // OSBuildVersion returns the version of osbuild. func OSBuildVersion() (string, error) { var stdoutBuffer bytes.Buffer - cmd := exec.Command(OSBuildCmd, "--version") + cmd := exec.Command(osbuildCmd, "--version") cmd.Stdout = &stdoutBuffer err := cmd.Run() @@ -173,7 +173,7 @@ func OSBuildVersion() (string, error) { // OSBuildInspect converts a manifest to an inspected manifest. func OSBuildInspect(manifest []byte) ([]byte, error) { - cmd := exec.Command(OSBuildCmd, "--inspect") + cmd := exec.Command(osbuildCmd, "--inspect") cmd.Stdin = bytes.NewBuffer(manifest) out, err := cmd.Output() diff --git a/pkg/osbuild/osbuild-exec_test.go b/pkg/osbuild/osbuild-exec_test.go index 074df1576a..1a8914d081 100644 --- a/pkg/osbuild/osbuild-exec_test.go +++ b/pkg/osbuild/osbuild-exec_test.go @@ -13,14 +13,6 @@ import ( "github.com/osbuild/images/pkg/osbuild" ) -func mockOsbuildCmd(s string) (restore func()) { - saved := osbuild.OSBuildCmd - osbuild.OSBuildCmd = s - return func() { - osbuild.OSBuildCmd = saved - } -} - func makeFakeOsbuild(t *testing.T, content string) string { p := filepath.Join(t.TempDir(), "fake-osbuild") err := os.WriteFile(p, []byte("#!/bin/sh\n"+content), 0755) @@ -117,7 +109,7 @@ else echo '{"success": true}' fi `) - restore := mockOsbuildCmd(fakeOsbuildBinary) + restore := osbuild.MockOsbuildCmd(fakeOsbuildBinary) defer restore() opts := &osbuild.OSBuildOptions{