command/init: Testing remote flags

This commit is contained in:
Armon Dadgar 2014-10-08 14:57:22 -07:00 committed by Mitchell Hashimoto
parent 34df217514
commit 722a885113
2 changed files with 49 additions and 3 deletions

View File

@ -5,6 +5,8 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/hashicorp/terraform/remote"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
) )
@ -142,3 +144,40 @@ func TestInit_dstInSrc(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
} }
func TestInit_remoteState(t *testing.T) {
tmp, cwd := testCwd(t)
defer fixDir(tmp, cwd)
s := terraform.NewState()
conf, srv := testRemoteState(t, s)
defer srv.Close()
ui := new(cli.MockUi)
c := &InitCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
},
}
args := []string{
"-remote", conf.Name,
"-remote-server", conf.Server,
testFixturePath("init"),
tmp,
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
if _, err := os.Stat(filepath.Join(tmp, "hello.tf")); err != nil {
t.Fatalf("err: %s", err)
}
path, _ := remote.HiddenStatePath()
_, err := os.Stat(path)
if err != nil {
t.Fatalf("missing state")
}
}

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"testing" "testing"
"github.com/hashicorp/terraform/remote" "github.com/hashicorp/terraform/remote"
@ -37,7 +38,7 @@ func TestPull_cliRemote(t *testing.T) {
defer fixDir(tmp, cwd) defer fixDir(tmp, cwd)
s := terraform.NewState() s := terraform.NewState()
remote, srv := testRemoteState(t, s) conf, srv := testRemoteState(t, s)
defer srv.Close() defer srv.Close()
ui := new(cli.MockUi) ui := new(cli.MockUi)
@ -48,13 +49,19 @@ func TestPull_cliRemote(t *testing.T) {
}, },
} }
args := []string{"-remote", remote.Name, "-remote-server", remote.Server} args := []string{"-remote", conf.Name, "-remote-server", conf.Server}
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())
} }
path, _ := remote.HiddenStatePath()
_, err := os.Stat(path)
if err != nil {
t.Fatalf("missing state")
}
} }
func TestPull_localRemote(t *testing.T) { func TestPull_local(t *testing.T) {
tmp, cwd := testCwd(t) tmp, cwd := testCwd(t)
defer fixDir(tmp, cwd) defer fixDir(tmp, cwd)