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.
This commit is contained in:
Martin Atkins 2018-11-14 16:31:56 -08:00
parent aecb66d3db
commit 2b9f92be31
2 changed files with 7 additions and 5 deletions

View File

@ -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)

View File

@ -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 {