From c3e943bed2878d4c47ed4ef7eb50e05ed3690b23 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 1 Aug 2017 17:50:53 -0400 Subject: [PATCH] add another failing test for remote.State lineage Want to make sure we don't hit this again. --- backend/remote-state/inmem/backend_test.go | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/backend/remote-state/inmem/backend_test.go b/backend/remote-state/inmem/backend_test.go index 1f4ab1138..005e66a1e 100644 --- a/backend/remote-state/inmem/backend_test.go +++ b/backend/remote-state/inmem/backend_test.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/state/remote" + "github.com/hashicorp/terraform/terraform" ) func TestBackend_impl(t *testing.T) { @@ -49,3 +50,41 @@ func TestBackendLocked(t *testing.T) { backend.TestBackend(t, b1, b2) } + +// use the this backen to test the remote.State implementation +func TestRemoteState(t *testing.T) { + defer Reset() + b := backend.TestBackendConfig(t, New(), nil) + + workspace := "workspace" + + // create a new workspace in this backend + s, err := b.State(workspace) + if err != nil { + t.Fatal(err) + } + + // force overwriting the remote state + newState := terraform.NewState() + + if err := s.WriteState(newState); err != nil { + t.Fatal(err) + } + + if err := s.PersistState(); err != nil { + t.Fatal(err) + } + + if err := s.RefreshState(); err != nil { + t.Fatal(err) + } + + savedState := s.State() + if err != nil { + t.Fatal(err) + } + + if savedState.Lineage != newState.Lineage { + t.Fatal("saved state has incorrect lineage") + } +}