refactor(fsrepo.test) use TempDir
@jbenet
Brian Tiger Chow committed
Jan 13, 2015 at 03:00 UTC
01f54d69660853ce651016df94c349e2dbff365a
3 files changed
+10
-17
repo/fsrepo/fsrepo_test.go
+10
-16
@@ -1,28 +1,22 @@
1
package fsrepo
2
3
import (
4
- "os"
5
- "path"
4
+ "io/ioutil"
5
"testing"
6
7
"github.com/jbenet/go-ipfs/repo/config"
8
)
9
11
-// NB: These tests cannot be run in parallel
12
-
13
-func init() {
14
- // ensure tests begin in clean state
15
- os.RemoveAll(testRepoDir)
16
-}
17
-
18
-const testRepoDir = "./fsrepo_test/repos"
19
-
20
-func testRepoPath(p string) string {
21
- return path.Join(testRepoDir, p)
10
+func testRepoPath(p string, t *testing.T) string {
11
+ name, err := ioutil.TempDir("", p)
12
+ if err != nil {
13
+ t.Fatal(err)
14
+ }
15
+ return name
16
}
17
18
func TestCannotRemoveIfOpen(t *testing.T) {
25
- path := testRepoPath("TestCannotRemoveIfOpen")
19
+ path := testRepoPath("TestCannotRemoveIfOpen", t)
20
AssertNil(Init(path, &config.Config{}), t, "should initialize successfully")
21
r := At(path)
22
AssertNil(r.Open(), t)
@@ -32,8 +26,8 @@ func TestCannotRemoveIfOpen(t *testing.T) {
26
}
27
28
func TestCanManageReposIndependently(t *testing.T) {
35
- pathA := testRepoPath("a")
36
- pathB := testRepoPath("b")
29
+ pathA := testRepoPath("a", t)
30
+ pathB := testRepoPath("b", t)
31
32
t.Log("initialize two repos")
33
AssertNil(Init(pathA, &config.Config{}), t, "should initialize successfully")
repo/fsrepo/fsrepo_test/.gitkeep
repo/fsrepo/fsrepo_test/README.md
deleted
-1
@@ -1 +0,0 @@
1
-This directory is used to store FSRepos generated during go tests.