Add remote state test for serial and lineage changes

We only persist a new state if the actual state contents have
changed. This test demonstrates that behavior by calling write
and persist methods when either the lineage or serial have changed.
This commit is contained in:
Lee Trout 2020-05-04 11:45:36 -04:00
parent 9debd341bc
commit c2c38b2ad3
1 changed files with 21 additions and 0 deletions

View File

@ -84,6 +84,27 @@ func TestStatePersist(t *testing.T) {
t.Fatalf("failed to PersistState: %s", err)
}
// We also don't persist state if the lineage or the serial change
originalSerial := mgr.serial
mgr.serial++
if err := mgr.WriteState(s); err != nil {
t.Fatalf("failed to WriteState: %s", err)
}
if err := mgr.PersistState(); err != nil {
t.Fatalf("failed to PersistState: %s", err)
}
mgr.serial = originalSerial
originalLineage := mgr.lineage
mgr.lineage = "behold-a-wild-lineage-appears"
if err := mgr.WriteState(s); err != nil {
t.Fatalf("failed to WriteState: %s", err)
}
if err := mgr.PersistState(); err != nil {
t.Fatalf("failed to PersistState: %s", err)
}
mgr.lineage = originalLineage
// ...but if we _do_ change something in the state then we should see
// it re-persist.
s.RootModule().SetOutputValue("foo", cty.StringVal("baz"), false)