From b51d1f983aa906399270ed05d76ffcaf0219af34 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 13 Mar 2025 21:24:11 +0100 Subject: [PATCH] image-builder: use testutil.Chdir() in TestBuildIntegrationHappy --- cmd/image-builder/main_test.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/cmd/image-builder/main_test.go b/cmd/image-builder/main_test.go index 365776a..6882fce 100644 --- a/cmd/image-builder/main_test.go +++ b/cmd/image-builder/main_test.go @@ -370,14 +370,6 @@ func TestBuildIntegrationHappy(t *testing.T) { defer restore() tmpdir := t.TempDir() - curdir, err := os.Getwd() - require.NoError(t, err) - err = os.Chdir(tmpdir) - require.NoError(t, err) - defer func() { - os.Chdir(curdir) - }() - restore = main.MockOsArgs([]string{ "build", "qcow2", @@ -391,7 +383,12 @@ func TestBuildIntegrationHappy(t *testing.T) { fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", script) defer fakeOsbuildCmd.Restore() - err = main.Run() + var err error + // run inside the tmpdir to validate that the default output dir + // creation works + testutil.Chdir(t, tmpdir, func() { + err = main.Run() + }) assert.NoError(t, err) assert.Contains(t, fakeStdout.String(), `Image build successful, result in "centos-9-qcow2-x86_64"`+"\n")