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

@ -1,8 +1,6 @@
package store
import (
"io/ioutil"
"os"
"testing"
"time"
@ -112,20 +110,13 @@ func (suite *storeTest) SetupSuite() {
//setup before each test
func (suite *storeTest) SetupTest() {
tmpDir, err := ioutil.TempDir("/tmp", "osbuild-composer-test-")
suite.NoError(err)
distro := test_distro.New()
arch, err := distro.GetArch(test_distro.TestArchName)
suite.NoError(err)
suite.dir = tmpDir
suite.dir = suite.T().TempDir()
suite.myStore = New(&suite.dir, arch, nil)
}
//teardown after each test
func (suite *storeTest) TearDownTest() {
os.RemoveAll(suite.dir)
}
func (suite *storeTest) TestRandomSHA1String() {
hash, err := randomSHA1String()
suite.NoError(err)