From 2b9f92be31ec0ec71bfb29fcc972c383dfe178f6 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 14 Nov 2018 16:31:56 -0800 Subject: [PATCH] command: Partially fix TestMetaBackend_planLocalStatePath This test is testing some strange implementation details of the old local backend which do not hold with the new filesystem state manager. Specifically, it was expecting state to be read from the stateOutPath rather than the statePath, which makes no sense here because the backend is configured to read from the default terraform.tfstate file (which does not exist.) There is another problem with this test which will be addressed in a subsequent commit. --- command/meta_backend.go | 3 +++ command/meta_backend_test.go | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/command/meta_backend.go b/command/meta_backend.go index 5ce527dbc..f519ebcec 100644 --- a/command/meta_backend.go +++ b/command/meta_backend.go @@ -171,6 +171,7 @@ func (m *Meta) BackendForPlan(settings plans.Backend) (backend.Enhanced, tfdiags return nil, diags } b := f() + log.Printf("[TRACE] Meta.BackendForPlan: instantiated backend of type %T", b) schema := b.ConfigSchema() configVal, err := settings.Config.Decode(schema.ImpliedType()) @@ -204,11 +205,13 @@ func (m *Meta) BackendForPlan(settings plans.Backend) (backend.Enhanced, tfdiags // If the result of loading the backend is an enhanced backend, // then return that as-is. This works even if b == nil (it will be !ok). if enhanced, ok := b.(backend.Enhanced); ok { + log.Printf("[TRACE] Meta.BackendForPlan: backend %T supports operations", b) return enhanced, nil } // Otherwise, we'll wrap our state-only remote backend in the local backend // to cause any operations to be run locally. + log.Printf("[TRACE] Meta.Backend: backend %T does not support operations, so wrapping it in a local backend", b) cliOpts := m.backendCLIOpts() cliOpts.Validation = false // don't validate here in case config contains file(...) calls where the file doesn't exist local := backendLocal.NewWithBackend(b) diff --git a/command/meta_backend_test.go b/command/meta_backend_test.go index d837eaff9..2adfbabb6 100644 --- a/command/meta_backend_test.go +++ b/command/meta_backend_test.go @@ -1549,7 +1549,7 @@ func TestMetaBackend_planLocalStatePath(t *testing.T) { if err != nil { t.Fatal(err) } - backendConfig := plans.Backend{ + plannedBackend := plans.Backend{ Type: "local", Config: backendConfigRaw, Workspace: "default", @@ -1569,7 +1569,7 @@ func TestMetaBackend_planLocalStatePath(t *testing.T) { m.stateOutPath = statePath // Get the backend - b, diags := m.BackendForPlan(backendConfig) + b, diags := m.BackendForPlan(plannedBackend) if diags.HasErrors() { t.Fatal(diags.Err()) } @@ -1583,10 +1583,9 @@ func TestMetaBackend_planLocalStatePath(t *testing.T) { t.Fatalf("unexpected error: %s", err) } state := s.State() - if state == nil { - t.Fatal("state is nil") + if state != nil { + t.Fatal("default workspace state is not nil, but should be because we've not put anything there") } - assertStateHasMarker(t, state, mark) // Verify the default path doesn't exist if _, err := os.Stat(DefaultStateFilename); err == nil {