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-07 16:55:12 +08:00
committed by Ramkumar Chinchani
parent 4be2652085
commit 0d77b60de7
19 changed files with 238 additions and 759 deletions
+2 -11
View File
@@ -398,12 +398,7 @@ func TestScrub(t *testing.T) {
config.HTTP.Port = port
controller := api.NewController(config)
dir, err := ioutil.TempDir("", "scrub-test")
if err != nil {
panic(err)
}
defer os.RemoveAll(dir)
dir := t.TempDir()
controller.Config.Storage.RootDirectory = dir
go func(controller *api.Controller) {
@@ -480,11 +475,7 @@ func TestScrub(t *testing.T) {
Convey("bad index.json", func(c C) {
port := GetFreePort()
dir, err := ioutil.TempDir("", "scrub-test")
if err != nil {
panic(err)
}
defer os.RemoveAll(dir)
dir := t.TempDir()
repoName := "badIndex"