add some Serial checks to apply and refresh tests
This commit is contained in:
parent
054716c397
commit
fb397060eb
|
@ -272,6 +272,14 @@ func TestApply_defaultState(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
// create an existing state file
|
||||
localState := &state.LocalState{Path: statePath}
|
||||
if err := localState.WriteState(terraform.NewState()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
serial := localState.State().Serial
|
||||
|
||||
args := []string{
|
||||
testFixturePath("apply"),
|
||||
}
|
||||
|
@ -287,6 +295,10 @@ func TestApply_defaultState(t *testing.T) {
|
|||
if state == nil {
|
||||
t.Fatal("state should not be nil")
|
||||
}
|
||||
|
||||
if state.Serial <= serial {
|
||||
t.Fatalf("serial was not incremented. previous:%d, current%d", serial, state.Serial)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApply_error(t *testing.T) {
|
||||
|
@ -540,10 +552,8 @@ func TestApply_plan_backup(t *testing.T) {
|
|||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
{
|
||||
// Should have a backup file
|
||||
testStateRead(t, backupPath)
|
||||
}
|
||||
// Should have a backup file
|
||||
testStateRead(t, backupPath)
|
||||
}
|
||||
|
||||
func TestApply_plan_noBackup(t *testing.T) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/copy"
|
||||
"github.com/hashicorp/terraform/state"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
@ -193,15 +194,11 @@ func TestRefresh_defaultState(t *testing.T) {
|
|||
}
|
||||
statePath := filepath.Join(td, DefaultStateFilename)
|
||||
|
||||
f, err := os.Create(statePath)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
err = terraform.WriteState(originalState, f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
localState := &state.LocalState{Path: statePath}
|
||||
if err := localState.WriteState(originalState); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
serial := localState.State().Serial
|
||||
|
||||
// Change to that directory
|
||||
cwd, err := os.Getwd()
|
||||
|
@ -236,16 +233,7 @@ func TestRefresh_defaultState(t *testing.T) {
|
|||
t.Fatal("refresh should be called")
|
||||
}
|
||||
|
||||
f, err = os.Open(statePath)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
newState, err := terraform.ReadState(f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
newState := testStateRead(t, statePath)
|
||||
|
||||
actual := newState.RootModule().Resources["test_instance.foo"].Primary
|
||||
expected := p.RefreshReturn
|
||||
|
@ -254,16 +242,11 @@ func TestRefresh_defaultState(t *testing.T) {
|
|||
t.Fatalf("bad:\n%#v", actual)
|
||||
}
|
||||
|
||||
f, err = os.Open(statePath + DefaultBackupExtension)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
if newState.Serial <= serial {
|
||||
t.Fatalf("serial not incremented during refresh. previous:%d, current:%d", serial, newState.Serial)
|
||||
}
|
||||
|
||||
backupState, err := terraform.ReadState(f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
backupState := testStateRead(t, statePath+DefaultBackupExtension)
|
||||
|
||||
actual = backupState.RootModule().Resources["test_instance.foo"].Primary
|
||||
expected = originalState.RootModule().Resources["test_instance.foo"].Primary
|
||||
|
|
Loading…
Reference in New Issue