test(fsrepo): InitIdempotence, NilRemoval, ReopeningDisallowed
Brian Tiger Chow committed
Jan 14, 2015 at 09:05 UTC
b685f92c953f202c9bf05df56c23d78038e8c4c9
1 file changed
+24
repo/fsrepo/fsrepo_test.go
+24
@@ -15,6 +15,18 @@ func testRepoPath(p string, t *testing.T) string {
15
return name
16
}
17
18
+func TestInitIdempotence(t *testing.T) {
19
+ path := testRepoPath("", t)
20
+ for i := 0; i < 10; i++ {
21
+ AssertNil(Init(path, &config.Config{}), t, "multiple calls to init should succeed")
22
+ }
23
+}
24
+
25
+func TestRemove(t *testing.T) {
26
+ path := testRepoPath("foo", t)
27
+ AssertNil(Remove(path), t, "should be able to remove after closed")
28
+}
29
+
30
func TestCannotRemoveIfOpen(t *testing.T) {
31
path := testRepoPath("TestCannotRemoveIfOpen", t)
32
AssertNil(Init(path, &config.Config{}), t, "should initialize successfully")
@@ -25,6 +37,18 @@ func TestCannotRemoveIfOpen(t *testing.T) {
37
AssertNil(Remove(path), t, "should be able to remove after closed")
38
}
39
40
+func TestCannotBeReopened(t *testing.T) {
41
+ path := testRepoPath("", t)
42
+ AssertNil(Init(path, &config.Config{}), t)
43
+ r := At(path)
44
+ AssertNil(r.Open(), t)
45
+ AssertNil(r.Close(), t)
46
+ AssertErr(r.Open(), t, "shouldn't be possible to re-open the repo")
47
+
48
+ // mutable state is the enemy. Take Close() as an opportunity to reduce
49
+ // entropy. Callers ought to start fresh with a new handle by calling `At`.
50
+}
51
+
52
func TestCanManageReposIndependently(t *testing.T) {
53
pathA := testRepoPath("a", t)
54
pathB := testRepoPath("b", t)