From c8ac05b39e7186321066f91338941a5544e6c3e8 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Wed, 15 Oct 2014 15:03:58 -0700 Subject: [PATCH] consul: Fixing FSM path tests --- consul/fsm_test.go | 87 ++++++++++++++++++++++++++++++++++++-------- consul/issue_test.go | 7 +++- 2 files changed, 78 insertions(+), 16 deletions(-) diff --git a/consul/fsm_test.go b/consul/fsm_test.go index db27ac6c2f..5e6b1ad370 100644 --- a/consul/fsm_test.go +++ b/consul/fsm_test.go @@ -2,6 +2,7 @@ package consul import ( "bytes" + "io/ioutil" "os" "testing" @@ -37,7 +38,11 @@ func makeLog(buf []byte) *raft.Log { } func TestFSM_RegisterNode(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -73,7 +78,11 @@ func TestFSM_RegisterNode(t *testing.T) { } func TestFSM_RegisterNode_Service(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -126,7 +135,11 @@ func TestFSM_RegisterNode_Service(t *testing.T) { } func TestFSM_DeregisterService(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -181,7 +194,11 @@ func TestFSM_DeregisterService(t *testing.T) { } func TestFSM_DeregisterCheck(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -236,7 +253,11 @@ func TestFSM_DeregisterCheck(t *testing.T) { } func TestFSM_DeregisterNode(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -303,7 +324,11 @@ func TestFSM_DeregisterNode(t *testing.T) { } func TestFSM_SnapshotRestore(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -347,7 +372,7 @@ func TestFSM_SnapshotRestore(t *testing.T) { } // Try to restore on a new FSM - fsm2, err := NewFSM(os.Stderr) + fsm2, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -409,7 +434,11 @@ func TestFSM_SnapshotRestore(t *testing.T) { } func TestFSM_KVSSet(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -444,7 +473,11 @@ func TestFSM_KVSSet(t *testing.T) { } func TestFSM_KVSDelete(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -490,7 +523,11 @@ func TestFSM_KVSDelete(t *testing.T) { } func TestFSM_KVSDeleteTree(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -537,7 +574,11 @@ func TestFSM_KVSDeleteTree(t *testing.T) { } func TestFSM_KVSCheckAndSet(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -594,7 +635,11 @@ func TestFSM_KVSCheckAndSet(t *testing.T) { } func TestFSM_SessionCreate_Destroy(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -674,7 +719,11 @@ func TestFSM_SessionCreate_Destroy(t *testing.T) { } func TestFSM_KVSLock(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -719,7 +768,11 @@ func TestFSM_KVSLock(t *testing.T) { } func TestFSM_KVSUnlock(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } @@ -782,7 +835,11 @@ func TestFSM_KVSUnlock(t *testing.T) { } func TestFSM_ACL_Set_Delete(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) } diff --git a/consul/issue_test.go b/consul/issue_test.go index 6bcd66e8a3..77bca7ce98 100644 --- a/consul/issue_test.go +++ b/consul/issue_test.go @@ -1,6 +1,7 @@ package consul import ( + "io/ioutil" "os" "reflect" "testing" @@ -10,7 +11,11 @@ import ( // Testing for GH-300 and GH-279 func TestHealthCheckRace(t *testing.T) { - fsm, err := NewFSM(os.Stderr) + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + fsm, err := NewFSM(path, os.Stderr) if err != nil { t.Fatalf("err: %v", err) }