backend/local: more tests passing

I have no confidence in the change to plans/planfile/tfplan.go. The
tests were passing an empty backend config, which planfile  was able to
write to a file but not read from the same file. This change let me move
past that and it did not break any tests in the planfile package, but I
am concerned that it introduces undesired behavior.
This commit is contained in:
Kristin Laemmert 2018-10-04 14:37:14 -07:00 committed by Martin Atkins
parent 56b879d0c0
commit 6a37ee9277
3 changed files with 16 additions and 13 deletions

View File

@ -171,7 +171,6 @@ func (b *Local) opPlan(
path, path,
))
}
}
}
}

View File

@ -131,10 +131,11 @@ func TestLocal_planNoConfig(t *testing.T) {
func TestLocal_planRefreshFalse(t *testing.T) {
b, cleanup := TestLocal(t)
defer cleanup()
p := TestLocalProvider(t, b, "test", &terraform.ProviderSchema{})
p := TestLocalProvider(t, b, "test", planFixtureSchema())
terraform.TestStateFile(t, b.StatePath, testPlanState())
op, configCleanup := testOperationPlan(t, "./test-fixtures/empty")
op, configCleanup := testOperationPlan(t, "./test-fixtures/plan")
defer configCleanup()
run, err := b.Operation(context.Background(), op)
@ -158,6 +159,7 @@ func TestLocal_planRefreshFalse(t *testing.T) {
func TestLocal_planDestroy(t *testing.T) {
b, cleanup := TestLocal(t)
defer cleanup()
p := TestLocalProvider(t, b, "test", planFixtureSchema())
terraform.TestStateFile(t, b.StatePath, testPlanState())
@ -167,7 +169,7 @@ func TestLocal_planDestroy(t *testing.T) {
op, configCleanup := testOperationPlan(t, "./test-fixtures/plan")
defer configCleanup()
op.Destroy = false
op.Destroy = true
op.PlanRefresh = true
op.PlanOutPath = planPath
@ -189,16 +191,11 @@ func TestLocal_planDestroy(t *testing.T) {
}
plan := testReadPlan(t, planPath)
// This statement can be removed when the test is fixed and replaced with the
// commented-out test below.
if plan == nil {
t.Fatalf("plan is nil")
for _, r := range plan.Changes.Resources {
if r.Action.String() != "Delete" {
t.Fatalf("bad: %#v", r.Action.String())
}
}
// for _, r := range plan.Changes.Resources {
// if !r.Destroy {
// t.Fatalf("bad: %#v", r)
// }
// }
}
func TestLocal_planOutPathNoChange(t *testing.T) {
@ -340,6 +337,9 @@ func testReadPlan(t *testing.T, path string) *plans.Plan {
defer p.Close()
plan, err := p.ReadPlan()
if err != nil {
t.Fatalf("err: %s", err)
}
return plan
}

View File

@ -277,6 +277,10 @@ func changeFromTfplan(rawChange *planproto.Change) (*plans.ChangeSrc, error) {
}
func valueFromTfplan(rawV *planproto.DynamicValue) (plans.DynamicValue, error) {
if rawV.Msgpack == nil {
return plans.DynamicValue(nil), nil
}
if len(rawV.Msgpack) == 0 { // len(0) because that's the default value for a "bytes" in protobuf
return nil, fmt.Errorf("dynamic value does not have msgpack serialization")
}