From f4cc2c066fa0385e974adab13cfb415175b552ea Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 26 Sep 2014 16:30:49 -0700 Subject: [PATCH] command: init works at a basic level --- command/init.go | 18 ++++++++++++------ command/init_test.go | 21 ++++++++++----------- command/test-fixtures/init/hello.tf | 0 3 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 command/test-fixtures/init/hello.tf diff --git a/command/init.go b/command/init.go index dc7afda3a..2a9c6f45d 100644 --- a/command/init.go +++ b/command/init.go @@ -3,7 +3,6 @@ package command import ( "flag" "fmt" - "io/ioutil" "os" "strings" @@ -50,6 +49,14 @@ func (c *InitCommand) Run(args []string) int { source := args[0] + // Get our pwd since we need it + pwd, err := os.Getwd() + if err != nil { + c.Ui.Error(fmt.Sprintf( + "Error reading working directory: %s", err)) + return 1 + } + // Verify the directory is empty if empty, err := config.IsEmptyDir(path); err != nil { c.Ui.Error(fmt.Sprintf( @@ -63,17 +70,16 @@ func (c *InitCommand) Run(args []string) int { return 1 } - // Create a temporary directory to store our module - td, err := ioutil.TempDir("", "tf") + // Detect + source, err = module.Detect(source, pwd) if err != nil { c.Ui.Error(fmt.Sprintf( - "Error creating temporary directory: %s", err)) + "Error with module source: %s", err)) return 1 } - defer os.RemoveAll(td) // Get it! - if err := module.Get(td, source); err != nil { + if err := module.GetCopy(path, source); err != nil { c.Ui.Error(err.Error()) return 1 } diff --git a/command/init_test.go b/command/init_test.go index 7238bc6ce..c1cc56a37 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -1,15 +1,18 @@ package command import ( + "os" + "path/filepath" "testing" "github.com/mitchellh/cli" ) -/* -func TestGet(t *testing.T) { +func TestInit(t *testing.T) { + dir := tempDir(t) + ui := new(cli.MockUi) - c := &GetCommand{ + c := &InitCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -17,21 +20,17 @@ func TestGet(t *testing.T) { } args := []string{ - testFixturePath("get"), + testFixturePath("init"), + dir, } if code := c.Run(args); code != 0 { t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) } - output := ui.OutputWriter.String() - if !strings.Contains(output, "Get: file://") { - t.Fatalf("doesn't look like get: %s", output) - } - if strings.Contains(output, "(update)") { - t.Fatalf("doesn't look like get: %s", output) + if _, err := os.Stat(filepath.Join(dir, "hello.tf")); err != nil { + t.Fatalf("err: %s", err) } } -*/ func TestInit_multipleArgs(t *testing.T) { ui := new(cli.MockUi) diff --git a/command/test-fixtures/init/hello.tf b/command/test-fixtures/init/hello.tf new file mode 100644 index 000000000..e69de29bb