|
|
|
|
@ -28,9 +28,7 @@ func TestState(t *testing.T, s interface{}) {
|
|
|
|
|
current := TestStateInitial()
|
|
|
|
|
|
|
|
|
|
// Check that the initial state is correct
|
|
|
|
|
state := reader.State()
|
|
|
|
|
current.Serial = state.Serial
|
|
|
|
|
if !reflect.DeepEqual(state, current) {
|
|
|
|
|
if state := reader.State(); !current.Equal(state) {
|
|
|
|
|
t.Fatalf("not initial: %#v\n\n%#v", state, current)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -47,7 +45,7 @@ func TestState(t *testing.T, s interface{}) {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if actual := reader.State(); !reflect.DeepEqual(actual, current) {
|
|
|
|
|
if actual := reader.State(); !actual.Equal(current) {
|
|
|
|
|
t.Fatalf("bad: %#v\n\n%#v", actual, current)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -67,11 +65,55 @@ func TestState(t *testing.T, s interface{}) {
|
|
|
|
|
|
|
|
|
|
// Just set the serials the same... Then compare.
|
|
|
|
|
actual := reader.State()
|
|
|
|
|
actual.Serial = current.Serial
|
|
|
|
|
if !reflect.DeepEqual(actual, current) {
|
|
|
|
|
if !actual.Equal(current) {
|
|
|
|
|
t.Fatalf("bad: %#v\n\n%#v", actual, current)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we can write and persist then verify that the serial
|
|
|
|
|
// is only implemented on change.
|
|
|
|
|
writer, writeOk := s.(StateWriter)
|
|
|
|
|
persister, persistOk := s.(StatePersister)
|
|
|
|
|
if writeOk && persistOk {
|
|
|
|
|
// Same serial
|
|
|
|
|
serial := current.Serial
|
|
|
|
|
if err := writer.WriteState(current); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if err := persister.PersistState(); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if reader.State().Serial != serial {
|
|
|
|
|
t.Fatalf("bad: expected %d, got %d", serial, reader.State().Serial)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Change the serial
|
|
|
|
|
currentCopy := *current
|
|
|
|
|
current = ¤tCopy
|
|
|
|
|
current.Modules = []*terraform.ModuleState{
|
|
|
|
|
&terraform.ModuleState{
|
|
|
|
|
Path: []string{"root", "somewhere"},
|
|
|
|
|
Outputs: map[string]string{"serialCheck": "true"},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
if err := writer.WriteState(current); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if err := persister.PersistState(); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if reader.State().Serial <= serial {
|
|
|
|
|
t.Fatalf("bad: expected %d, got %d", serial, reader.State().Serial)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that State() returns a copy
|
|
|
|
|
reader.State().Serial++
|
|
|
|
|
if reflect.DeepEqual(reader.State(), current) {
|
|
|
|
|
t.Fatal("State() should return a copy")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestStateInitial is the initial state that a State should have
|
|
|
|
|
|