command: fix some issues with refresh, tests passing
This commit is contained in:
parent
7fd1a06426
commit
d3d45ca064
|
@ -40,6 +40,10 @@ func TestPlan_destroy(t *testing.T) {
|
||||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !p.RefreshCalled {
|
||||||
|
t.Fatal("refresh should be called")
|
||||||
|
}
|
||||||
|
|
||||||
plan := testReadPlan(t, outPath)
|
plan := testReadPlan(t, outPath)
|
||||||
for _, r := range plan.Diff.Resources {
|
for _, r := range plan.Diff.Resources {
|
||||||
if !r.Destroy {
|
if !r.Destroy {
|
||||||
|
@ -63,8 +67,8 @@ func TestPlan_noState(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that refresh was called
|
// Verify that refresh was called
|
||||||
if !p.RefreshCalled {
|
if p.RefreshCalled {
|
||||||
t.Fatal("refresh should be called")
|
t.Fatal("refresh should not be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that the provider was called with the existing state
|
// Verify that the provider was called with the existing state
|
||||||
|
|
|
@ -67,6 +67,7 @@ func (c *RefreshCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ContextOpts.Config = b
|
c.ContextOpts.Config = b
|
||||||
|
c.ContextOpts.State = state
|
||||||
c.ContextOpts.Hooks = append(c.ContextOpts.Hooks, &UiHook{Ui: c.Ui})
|
c.ContextOpts.Hooks = append(c.ContextOpts.Hooks, &UiHook{Ui: c.Ui})
|
||||||
ctx := terraform.NewContext(c.ContextOpts)
|
ctx := terraform.NewContext(c.ContextOpts)
|
||||||
if !validateContext(ctx, c.Ui) {
|
if !validateContext(ctx, c.Ui) {
|
||||||
|
|
|
@ -11,21 +11,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRefresh(t *testing.T) {
|
func TestRefresh(t *testing.T) {
|
||||||
// Write out some prior state
|
state := &terraform.State{
|
||||||
tf, err := ioutil.TempFile("", "tf")
|
Resources: map[string]*terraform.ResourceState{
|
||||||
if err != nil {
|
"test_instance.foo": &terraform.ResourceState{
|
||||||
t.Fatalf("err: %s", err)
|
ID: "bar",
|
||||||
}
|
Type: "test_instance",
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
statePath := testStateFile(t, state)
|
||||||
|
|
||||||
p := testProvider()
|
p := testProvider()
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
|
@ -68,13 +62,15 @@ func TestRefresh(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRefresh_outPath(t *testing.T) {
|
func TestRefresh_outPath(t *testing.T) {
|
||||||
// Write out some prior state
|
state := &terraform.State{
|
||||||
tf, err := ioutil.TempFile("", "tf")
|
Resources: map[string]*terraform.ResourceState{
|
||||||
if err != nil {
|
"test_instance.foo": &terraform.ResourceState{
|
||||||
t.Fatalf("err: %s", err)
|
ID: "bar",
|
||||||
|
Type: "test_instance",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
statePath := tf.Name()
|
statePath := testStateFile(t, state)
|
||||||
defer os.Remove(tf.Name())
|
|
||||||
|
|
||||||
// Output path
|
// Output path
|
||||||
outf, err := ioutil.TempFile("", "tf")
|
outf, err := ioutil.TempFile("", "tf")
|
||||||
|
@ -85,14 +81,6 @@ func TestRefresh_outPath(t *testing.T) {
|
||||||
outf.Close()
|
outf.Close()
|
||||||
os.Remove(outPath)
|
os.Remove(outPath)
|
||||||
|
|
||||||
state := &terraform.State{}
|
|
||||||
|
|
||||||
err = terraform.WriteState(state, tf)
|
|
||||||
tf.Close()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
p := testProvider()
|
p := testProvider()
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &RefreshCommand{
|
c := &RefreshCommand{
|
||||||
|
|
Loading…
Reference in New Issue