command: Fix TestPlan_outBackend

We missed fixing this up during the big updates for the new plan/state
models since the failures were being masked by testBackendState being
broken.

This is the same sort of update made to many other tests: add schema to
the mock provider, adjust for the new plan/state types, and make
allowances for the new built-in diffing behavior in core.
This commit is contained in:
Martin Atkins 2018-11-07 17:43:46 -08:00
parent c3d11b762b
commit 1e45d30036
1 changed files with 44 additions and 5 deletions

View File

@ -5,7 +5,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
"sync"
"testing"
@ -16,6 +15,7 @@ import (
"github.com/zclconf/go-cty/cty"
"github.com/hashicorp/terraform/addrs"
backendinit "github.com/hashicorp/terraform/backend/init"
"github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/helper/copy"
"github.com/hashicorp/terraform/plans"
@ -290,6 +290,9 @@ func TestPlan_outBackend(t *testing.T) {
Type: "test_instance",
Primary: &terraform.InstanceState{
ID: "bar",
Attributes: map[string]string{
"ami": "bar",
},
},
},
},
@ -305,6 +308,27 @@ func TestPlan_outBackend(t *testing.T) {
outPath := "foo"
p := testProvider()
p.GetSchemaReturn = &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"id": {
Type: cty.String,
Computed: true,
},
"ami": {
Type: cty.String,
Optional: true,
},
},
},
},
}
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
return providers.PlanResourceChangeResponse{
PlannedState: req.ProposedNewState,
}
}
ui := cli.NewMockUi()
c := &PlanCommand{
Meta: Meta{
@ -326,11 +350,26 @@ func TestPlan_outBackend(t *testing.T) {
t.Fatalf("Expected empty plan to be written to plan file, got: %s", spew.Sdump(plan))
}
if plan.Backend.Type == "" || plan.Backend.Config == nil {
t.Fatal("should have backend info")
if got, want := plan.Backend.Type, "http"; got != want {
t.Errorf("wrong backend type %q; want %q", got, want)
}
if !reflect.DeepEqual(plan.Backend, dataState.Backend) {
t.Fatalf("wrong backend config in plan\ngot: %swant: %s", spew.Sdump(plan.Backend), spew.Sdump(dataState.Backend))
if got, want := plan.Backend.Workspace, "default"; got != want {
t.Errorf("wrong backend workspace %q; want %q", got, want)
}
{
httpBackend := backendinit.Backend("http")()
schema := httpBackend.ConfigSchema()
got, err := plan.Backend.Config.Decode(schema.ImpliedType())
if err != nil {
t.Fatalf("failed to decode backend config in plan: %s", err)
}
want, err := dataState.Backend.Config(schema)
if err != nil {
t.Fatalf("failed to decode cached config: %s", err)
}
if !want.RawEquals(got) {
t.Errorf("wrong backend config\ngot: %#v\nwant: %#v", got, want)
}
}
}