From 82e4bab178171490cd71983e3c42b0558967c996 Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Tue, 4 Nov 2014 21:19:39 +0100 Subject: [PATCH] command/init: test for issue 518 --- command/init_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/command/init_test.go b/command/init_test.go index 2db54b047..1321fc089 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -100,3 +100,45 @@ func TestInit_noArgs(t *testing.T) { t.Fatalf("bad: \n%s", ui.OutputWriter.String()) } } + +// https://github.com/hashicorp/terraform/issues/518 +func TestIssue518(t *testing.T) { + dir := tempDir(t) + if err := os.MkdirAll(dir, 0755); err != nil { + t.Fatalf("err: %s", err) + } + + // Change to the temporary directory + cwd, err := os.Getwd() + if err != nil { + t.Fatalf("err: %s", err) + } + if err := os.Chdir(dir); err != nil { + t.Fatalf("err: %s", err) + } + defer os.Chdir(cwd) + + if _, err := os.Create("issue518.tf"); err != nil { + t.Fatalf("err: %s", err) + } + + ui := new(cli.MockUi) + c := &InitCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + }, + } + + args := []string{ + ".", + "foo", + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) + } + + if _, err := os.Stat(filepath.Join(dir, "foo", "issue518.tf")); err != nil { + t.Fatalf("err: %s", err) + } +}