Create state files first for backup tests

Previously when runnign a plan with no exitsing state, the plan would be
written out and then backed up on the next WriteState by another
BackupState instance. Since we now maintain a single State instance
thoughout an operation, the backup happens before any state exists so no
backup file is created.

This is OK, as the backup state the tests were checking for is from the
plan file, which already exists separate from the state.
This commit is contained in:
James Bardin 2017-02-03 13:07:34 -05:00
parent dd19cb202d
commit 94f2f4d6ae
2 changed files with 16 additions and 1 deletions

View File

@ -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,

View File

@ -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