From 09d7fb7c2748e007963f870edc2198ae476269ce Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 9 Oct 2014 14:45:08 -0700 Subject: [PATCH] command: cleanup test function names --- command/command_test.go | 16 +++++++++++----- command/init_test.go | 2 +- command/pull_test.go | 6 +++--- command/push_test.go | 8 ++++---- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/command/command_test.go b/command/command_test.go index 295dc1579..996178f49 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -186,12 +186,18 @@ func testCwd(t *testing.T) (string, string) { if err != nil { t.Fatalf("err: %v", err) } - os.Chdir(tmp) + if err := os.Chdir(tmp); err != nil { + t.Fatalf("err: %v", err) + } return tmp, cwd } -// fixDir is used to as a defer to testDir -func fixDir(tmp, cwd string) { - os.Chdir(cwd) - os.RemoveAll(tmp) +// testFixCwd is used to as a defer to testDir +func testFixCwd(t *testing.T, tmp, cwd string) { + if err := os.Chdir(cwd); err != nil { + t.Fatalf("err: %v", err) + } + if err := os.RemoveAll(tmp); err != nil { + t.Fatalf("err: %v", err) + } } diff --git a/command/init_test.go b/command/init_test.go index b99bc0493..3c6011233 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -147,7 +147,7 @@ func TestInit_dstInSrc(t *testing.T) { func TestInit_remoteState(t *testing.T) { tmp, cwd := testCwd(t) - defer fixDir(tmp, cwd) + defer testFixCwd(t, tmp, cwd) s := terraform.NewState() conf, srv := testRemoteState(t, s, 200) diff --git a/command/pull_test.go b/command/pull_test.go index 7b8a555b8..cc716cd99 100644 --- a/command/pull_test.go +++ b/command/pull_test.go @@ -17,7 +17,7 @@ import ( func TestPull_noRemote(t *testing.T) { tmp, cwd := testCwd(t) - defer fixDir(tmp, cwd) + defer testFixCwd(t, tmp, cwd) ui := new(cli.MockUi) c := &PullCommand{ @@ -35,7 +35,7 @@ func TestPull_noRemote(t *testing.T) { func TestPull_cliRemote(t *testing.T) { tmp, cwd := testCwd(t) - defer fixDir(tmp, cwd) + defer testFixCwd(t, tmp, cwd) s := terraform.NewState() conf, srv := testRemoteState(t, s, 200) @@ -63,7 +63,7 @@ func TestPull_cliRemote(t *testing.T) { func TestPull_local(t *testing.T) { tmp, cwd := testCwd(t) - defer fixDir(tmp, cwd) + defer testFixCwd(t, tmp, cwd) s := terraform.NewState() s.Serial = 10 diff --git a/command/push_test.go b/command/push_test.go index 0801228d7..17621a4a2 100644 --- a/command/push_test.go +++ b/command/push_test.go @@ -13,7 +13,7 @@ import ( func TestPush_noRemote(t *testing.T) { tmp, cwd := testCwd(t) - defer fixDir(tmp, cwd) + defer testFixCwd(t, tmp, cwd) ui := new(cli.MockUi) c := &PushCommand{ @@ -31,7 +31,7 @@ func TestPush_noRemote(t *testing.T) { func TestPush_cliRemote_noState(t *testing.T) { tmp, cwd := testCwd(t) - defer fixDir(tmp, cwd) + defer testFixCwd(t, tmp, cwd) s := terraform.NewState() conf, srv := testRemoteState(t, s, 200) @@ -54,7 +54,7 @@ func TestPush_cliRemote_noState(t *testing.T) { func TestPush_cliRemote_withState(t *testing.T) { tmp, cwd := testCwd(t) - defer fixDir(tmp, cwd) + defer testFixCwd(t, tmp, cwd) s := terraform.NewState() conf, srv := testRemoteState(t, s, 200) @@ -98,7 +98,7 @@ func TestPush_cliRemote_withState(t *testing.T) { func TestPush_local(t *testing.T) { tmp, cwd := testCwd(t) - defer fixDir(tmp, cwd) + defer testFixCwd(t, tmp, cwd) s := terraform.NewState() s.Serial = 5