From c2c38b2ad3f09a2352f79d97ff6292bf4d9d771d Mon Sep 17 00:00:00 2001 From: Lee Trout Date: Mon, 4 May 2020 11:45:36 -0400 Subject: [PATCH] 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. --- state/remote/state_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/state/remote/state_test.go b/state/remote/state_test.go index 949eefe11..93a922ee0 100644 --- a/state/remote/state_test.go +++ b/state/remote/state_test.go @@ -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)