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

@ -5,9 +5,7 @@
package main
import (
"io/ioutil"
"net/http"
"os"
"path"
"testing"
@ -63,9 +61,7 @@ func TestCrossArchDepsolve(t *testing.T) {
t.Parallel()
// Set up temporary directory for rpm/dnf cache
dir, err := ioutil.TempDir("/tmp", "rpmmd-test-")
require.Nilf(t, err, "Failed to create tmp dir for depsolve test: %v", err)
defer os.RemoveAll(dir)
dir := t.TempDir()
// use a fullpath to dnf-json, this allows this test to have an arbitrary
// working directory