command: fix some issues with refresh, tests passing

This commit is contained in:
Mitchell Hashimoto 2014-07-07 21:12:12 -07:00
parent 7fd1a06426
commit d3d45ca064
3 changed files with 23 additions and 30 deletions

View File

@ -40,6 +40,10 @@ func TestPlan_destroy(t *testing.T) {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
if !p.RefreshCalled {
t.Fatal("refresh should be called")
}
plan := testReadPlan(t, outPath)
for _, r := range plan.Diff.Resources {
if !r.Destroy {
@ -63,8 +67,8 @@ func TestPlan_noState(t *testing.T) {
}
// Verify that refresh was called
if !p.RefreshCalled {
t.Fatal("refresh should be called")
if p.RefreshCalled {
t.Fatal("refresh should not be called")
}
// Verify that the provider was called with the existing state

View File

@ -67,6 +67,7 @@ func (c *RefreshCommand) Run(args []string) int {
}
c.ContextOpts.Config = b
c.ContextOpts.State = state
c.ContextOpts.Hooks = append(c.ContextOpts.Hooks, &UiHook{Ui: c.Ui})
ctx := terraform.NewContext(c.ContextOpts)
if !validateContext(ctx, c.Ui) {

View File

@ -11,21 +11,15 @@ import (
)
func TestRefresh(t *testing.T) {
// Write out some prior state
tf, err := ioutil.TempFile("", "tf")
if err != nil {
t.Fatalf("err: %s", err)
}
statePath := tf.Name()
defer os.Remove(tf.Name())
state := &terraform.State{}
err = terraform.WriteState(state, tf)
tf.Close()
if err != nil {
t.Fatalf("err: %s", err)
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
statePath := testStateFile(t, state)
p := testProvider()
ui := new(cli.MockUi)
@ -68,13 +62,15 @@ func TestRefresh(t *testing.T) {
}
func TestRefresh_outPath(t *testing.T) {
// Write out some prior state
tf, err := ioutil.TempFile("", "tf")
if err != nil {
t.Fatalf("err: %s", err)
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
statePath := tf.Name()
defer os.Remove(tf.Name())
statePath := testStateFile(t, state)
// Output path
outf, err := ioutil.TempFile("", "tf")
@ -85,14 +81,6 @@ func TestRefresh_outPath(t *testing.T) {
outf.Close()
os.Remove(outPath)
state := &terraform.State{}
err = terraform.WriteState(state, tf)
tf.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
p := testProvider()
ui := new(cli.MockUi)
c := &RefreshCommand{