command: init works at a basic level
This commit is contained in:
parent
6cbadf14df
commit
f4cc2c066f
|
@ -3,7 +3,6 @@ package command
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -50,6 +49,14 @@ func (c *InitCommand) Run(args []string) int {
|
||||||
|
|
||||||
source := args[0]
|
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
|
// Verify the directory is empty
|
||||||
if empty, err := config.IsEmptyDir(path); err != nil {
|
if empty, err := config.IsEmptyDir(path); err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf(
|
c.Ui.Error(fmt.Sprintf(
|
||||||
|
@ -63,17 +70,16 @@ func (c *InitCommand) Run(args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a temporary directory to store our module
|
// Detect
|
||||||
td, err := ioutil.TempDir("", "tf")
|
source, err = module.Detect(source, pwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf(
|
c.Ui.Error(fmt.Sprintf(
|
||||||
"Error creating temporary directory: %s", err))
|
"Error with module source: %s", err))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(td)
|
|
||||||
|
|
||||||
// Get it!
|
// Get it!
|
||||||
if err := module.Get(td, source); err != nil {
|
if err := module.GetCopy(path, source); err != nil {
|
||||||
c.Ui.Error(err.Error())
|
c.Ui.Error(err.Error())
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
func TestInit(t *testing.T) {
|
||||||
func TestGet(t *testing.T) {
|
dir := tempDir(t)
|
||||||
|
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &GetCommand{
|
c := &InitCommand{
|
||||||
Meta: Meta{
|
Meta: Meta{
|
||||||
ContextOpts: testCtxConfig(testProvider()),
|
ContextOpts: testCtxConfig(testProvider()),
|
||||||
Ui: ui,
|
Ui: ui,
|
||||||
|
@ -17,21 +20,17 @@ func TestGet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
testFixturePath("get"),
|
testFixturePath("init"),
|
||||||
|
dir,
|
||||||
}
|
}
|
||||||
if code := c.Run(args); code != 0 {
|
if code := c.Run(args); code != 0 {
|
||||||
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
output := ui.OutputWriter.String()
|
if _, err := os.Stat(filepath.Join(dir, "hello.tf")); err != nil {
|
||||||
if !strings.Contains(output, "Get: file://") {
|
t.Fatalf("err: %s", err)
|
||||||
t.Fatalf("doesn't look like get: %s", output)
|
|
||||||
}
|
|
||||||
if strings.Contains(output, "(update)") {
|
|
||||||
t.Fatalf("doesn't look like get: %s", output)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
func TestInit_multipleArgs(t *testing.T) {
|
func TestInit_multipleArgs(t *testing.T) {
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
|
|
Loading…
Reference in New Issue