diff --git a/command/apply_test.go b/command/apply_test.go index 77667ae3e..72d52ddae 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -15,6 +15,7 @@ import ( "testing" "time" + "github.com/hashicorp/terraform/state" "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/cli" ) @@ -550,7 +551,8 @@ func TestApply_plan(t *testing.T) { } func TestApply_plan_backup(t *testing.T) { - planPath := testPlanFile(t, testPlan(t)) + plan := testPlan(t) + planPath := testPlanFile(t, plan) statePath := testTempFile(t) backupPath := testTempFile(t) @@ -563,6 +565,12 @@ func TestApply_plan_backup(t *testing.T) { }, } + // create a state file that needs to be backed up + err := (&state.LocalState{Path: statePath}).WriteState(plan.State) + if err != nil { + t.Fatal(err) + } + args := []string{ "-state-out", statePath, "-backup", backupPath, diff --git a/command/meta_backend_test.go b/command/meta_backend_test.go index c9cff296a..e73fa6b31 100644 --- a/command/meta_backend_test.go +++ b/command/meta_backend_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform/helper/copy" + "github.com/hashicorp/terraform/state" "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/cli" ) @@ -2208,6 +2209,12 @@ func TestMetaBackend_planLocalStatePath(t *testing.T) { // Create an alternate output path statePath := "foo.tfstate" + // put a initial state there that needs to be backed up + err := (&state.LocalState{Path: statePath}).WriteState(original) + if err != nil { + t.Fatal(err) + } + // Setup the meta m := testMetaBackend(t, nil) m.stateOutPath = statePath