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:
@@ -2,16 +2,11 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func genFsRepo(t *testing.T) (*FsRepo, func()) {
|
||||
path, err := ioutil.TempDir("", "lotus-repo-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
func genFsRepo(t *testing.T) *FsRepo {
|
||||
path := t.TempDir()
|
||||
|
||||
repo, err := NewFS(path)
|
||||
if err != nil {
|
||||
@@ -22,13 +17,10 @@ func genFsRepo(t *testing.T) (*FsRepo, func()) {
|
||||
if err != ErrRepoExists && err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return repo, func() {
|
||||
_ = os.RemoveAll(path)
|
||||
}
|
||||
return repo
|
||||
}
|
||||
|
||||
func TestFsBasic(t *testing.T) {
|
||||
repo, closer := genFsRepo(t)
|
||||
defer closer()
|
||||
repo := genFsRepo(t)
|
||||
basicTest(t, repo)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user