From 722a8851130f79f6468dac84f4bd16729afe3536 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Wed, 8 Oct 2014 14:57:22 -0700 Subject: [PATCH] command/init: Testing remote flags --- command/init_test.go | 39 +++++++++++++++++++++++++++++++++++++++ command/pull_test.go | 13 ++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/command/init_test.go b/command/init_test.go index ebd05e0f2..98495930b 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -5,6 +5,8 @@ import ( "path/filepath" "testing" + "github.com/hashicorp/terraform/remote" + "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/cli" ) @@ -142,3 +144,40 @@ func TestInit_dstInSrc(t *testing.T) { t.Fatalf("err: %s", err) } } + +func TestInit_remoteState(t *testing.T) { + tmp, cwd := testCwd(t) + defer fixDir(tmp, cwd) + + s := terraform.NewState() + conf, srv := testRemoteState(t, s) + defer srv.Close() + + ui := new(cli.MockUi) + c := &InitCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + }, + } + + args := []string{ + "-remote", conf.Name, + "-remote-server", conf.Server, + testFixturePath("init"), + tmp, + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) + } + + if _, err := os.Stat(filepath.Join(tmp, "hello.tf")); err != nil { + t.Fatalf("err: %s", err) + } + + path, _ := remote.HiddenStatePath() + _, err := os.Stat(path) + if err != nil { + t.Fatalf("missing state") + } +} diff --git a/command/pull_test.go b/command/pull_test.go index d5f47dd65..7a171e9b4 100644 --- a/command/pull_test.go +++ b/command/pull_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" "net/http" "net/http/httptest" + "os" "testing" "github.com/hashicorp/terraform/remote" @@ -37,7 +38,7 @@ func TestPull_cliRemote(t *testing.T) { defer fixDir(tmp, cwd) s := terraform.NewState() - remote, srv := testRemoteState(t, s) + conf, srv := testRemoteState(t, s) defer srv.Close() ui := new(cli.MockUi) @@ -48,13 +49,19 @@ func TestPull_cliRemote(t *testing.T) { }, } - args := []string{"-remote", remote.Name, "-remote-server", remote.Server} + args := []string{"-remote", conf.Name, "-remote-server", conf.Server} if code := c.Run(args); code != 0 { t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) } + + path, _ := remote.HiddenStatePath() + _, err := os.Stat(path) + if err != nil { + t.Fatalf("missing state") + } } -func TestPull_localRemote(t *testing.T) { +func TestPull_local(t *testing.T) { tmp, cwd := testCwd(t) defer fixDir(tmp, cwd)