test: use T.TempDir to create temporary test directory

The directory created by `T.TempDir` is automatically removed when the
test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun 2022-03-09 22:23:04 +08:00 committed by Ondřej Budai
parent c9a08da29f
commit 00ea3eb285
12 changed files with 104 additions and 392 deletions

View file

@ -3,7 +3,6 @@ package weldr
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"testing"
@ -22,11 +21,7 @@ func TestComposeStatusFromLegacyError(t *testing.T) {
t.Skip("This test is for internal testing only")
}
tempdir, err := ioutil.TempDir("", "weldr-tests-")
require.NoError(t, err)
defer os.RemoveAll(tempdir)
api, _ := createWeldrAPI(tempdir, rpmmd_mock.BaseFixture)
api, _ := createWeldrAPI(t.TempDir(), rpmmd_mock.BaseFixture)
distroStruct := test_distro.New()
arch, err := distroStruct.GetArch(test_distro.TestArchName)
@ -68,11 +63,7 @@ func TestComposeStatusFromJobError(t *testing.T) {
t.Skip("This test is for internal testing only")
}
tempdir, err := ioutil.TempDir("", "weldr-tests-")
require.NoError(t, err)
defer os.RemoveAll(tempdir)
api, _ := createWeldrAPI(tempdir, rpmmd_mock.BaseFixture)
api, _ := createWeldrAPI(t.TempDir(), rpmmd_mock.BaseFixture)
distroStruct := test_distro.New()
arch, err := distroStruct.GetArch(test_distro.TestArchName)