From c87f3dfdd54ddd06c2d2864f4e756a4d38d79bb2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 17 Mar 2017 10:22:48 -0700 Subject: [PATCH] command/init: add test for -backend-config k/v --- command/init_test.go | 27 +++++++++++++++++++ .../init-backend-config-kv/main.tf | 3 +++ 2 files changed, 30 insertions(+) create mode 100644 command/test-fixtures/init-backend-config-kv/main.tf diff --git a/command/init_test.go b/command/init_test.go index 295098c624..a3fa1b1dda 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -353,6 +353,33 @@ func TestInit_backendConfigFileChange(t *testing.T) { } } +func TestInit_backendConfigKV(t *testing.T) { + // Create a temporary working directory that is empty + td := tempDir(t) + copy.CopyDir(testFixturePath("init-backend-config-kv"), td) + defer os.RemoveAll(td) + defer testChdir(t, td)() + + ui := new(cli.MockUi) + c := &InitCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + }, + } + + args := []string{"-backend-config", "path=hello"} + if code := c.Run(args); code != 0 { + t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) + } + + // Read our saved backend config and verify we have our settings + state := testStateRead(t, filepath.Join(DefaultDataDir, DefaultStateFilename)) + if v := state.Backend.Config["path"]; v != "hello" { + t.Fatalf("bad: %#v", v) + } +} + func TestInit_copyBackendDst(t *testing.T) { // Create a temporary working directory that is empty td := tempDir(t) diff --git a/command/test-fixtures/init-backend-config-kv/main.tf b/command/test-fixtures/init-backend-config-kv/main.tf new file mode 100644 index 0000000000..c08b42fb03 --- /dev/null +++ b/command/test-fixtures/init-backend-config-kv/main.tf @@ -0,0 +1,3 @@ +terraform { + backend "local" {} +}