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

@ -4,9 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"testing"
"time"
@ -191,13 +189,9 @@ func runNextJob(t *testing.T, jobs []uuid.UUID, workerHandler http.Handler, orgI
// that all jobs are assigned to the correct channel, therefore we need also
// this test.
func TestMultitenancy(t *testing.T) {
dir, err := ioutil.TempDir("", "osbuild-composer-test-api-v2-")
require.NoError(t, err)
defer os.RemoveAll(dir)
// Passing an empty list as depsolving channels, we want to do depsolves
// ourselvess
apiServer, workerServer, q, cancel := newV2Server(t, dir, []string{}, true)
apiServer, workerServer, q, cancel := newV2Server(t, t.TempDir(), []string{}, true)
handler := apiServer.Handler("/api/image-builder-composer/v2")
defer cancel()