From bf1414336990448f3f02e792861114b18e1a4cb4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 6 Mar 2015 14:49:22 -0800 Subject: [PATCH] command/push: test that input is asked --- command/push.go | 3 +- command/push_test.go | 52 ++++++++++++++++++++++++ command/test-fixtures/push-input/main.tf | 3 ++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 command/test-fixtures/push-input/main.tf diff --git a/command/push.go b/command/push.go index 3430a9ab88..b884460409 100644 --- a/command/push.go +++ b/command/push.go @@ -1,7 +1,6 @@ package command import ( - "flag" "fmt" "io" "os" @@ -24,7 +23,7 @@ func (c *PushCommand) Run(args []string) int { var atlasToken string var moduleLock bool args = c.Meta.process(args, false) - cmdFlags := flag.NewFlagSet("push", flag.ContinueOnError) + cmdFlags := c.Meta.flagSet("push") cmdFlags.StringVar(&c.Meta.statePath, "state", DefaultStateFilename, "path") cmdFlags.StringVar(&atlasToken, "token", "", "") cmdFlags.BoolVar(&moduleLock, "module-lock", true, "") diff --git a/command/push_test.go b/command/push_test.go index e6ee2dc180..3c6415b624 100644 --- a/command/push_test.go +++ b/command/push_test.go @@ -2,6 +2,7 @@ package command import ( "archive/tar" + "bytes" "compress/gzip" "io" "os" @@ -65,6 +66,57 @@ func TestPush_good(t *testing.T) { } } +func TestPush_input(t *testing.T) { + tmp, cwd := testCwd(t) + defer testFixCwd(t, tmp, cwd) + + // Create remote state file, this should be pulled + conf, srv := testRemoteState(t, testState(), 200) + defer srv.Close() + + // Persist local remote state + s := terraform.NewState() + s.Serial = 5 + s.Remote = conf + testStateFileRemote(t, s) + + // Path where the archive will be "uploaded" to + archivePath := testTempFile(t) + defer os.Remove(archivePath) + + client := &mockPushClient{File: archivePath} + ui := new(cli.MockUi) + c := &PushCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + }, + + client: client, + } + + // Disable test mode so input would be asked and setup the + // input reader/writers. + test = false + defer func() { test = true }() + defaultInputReader = bytes.NewBufferString("foo\n") + defaultInputWriter = new(bytes.Buffer) + + args := []string{ + testFixturePath("push-input"), + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) + } + + variables := map[string]string{ + "foo": "foo", + } + if !reflect.DeepEqual(client.UpsertOptions.Variables, variables) { + t.Fatalf("bad: %#v", client.UpsertOptions) + } +} + func TestPush_noState(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) diff --git a/command/test-fixtures/push-input/main.tf b/command/test-fixtures/push-input/main.tf new file mode 100644 index 0000000000..55072f7125 --- /dev/null +++ b/command/test-fixtures/push-input/main.tf @@ -0,0 +1,3 @@ +variable "foo" {} + +resource "test_instance" "foo" {}