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-01-30 00:24:56 +08:00
committed by Nick Craig-Wood
parent 18c24014da
commit 8cf76f5e11
10 changed files with 26 additions and 94 deletions

View File

@ -2,7 +2,6 @@ package webgui
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -24,13 +23,12 @@ func init() {
}
func setCacheDir(t *testing.T) string {
cacheDir, err := ioutil.TempDir("", "rclone-cache-dir")
assert.Nil(t, err)
cacheDir := t.TempDir()
PluginsPath = filepath.Join(cacheDir, "plugins")
pluginsConfigPath = filepath.Join(cacheDir, "config")
loadedPlugins = newPlugins(availablePluginsJSONPath)
err = loadedPlugins.readFromFile()
err := loadedPlugins.readFromFile()
assert.Nil(t, err)
return cacheDir
}