command: Update plan_test.go for new provider types

This only makes it compile. It does not yet ensure that the tests pass.
This commit is contained in:
Martin Atkins 2018-09-30 07:54:32 -07:00
parent 54c1616d73
commit b195c712a3
1 changed files with 31 additions and 24 deletions

View File

@ -11,11 +11,14 @@ import (
"testing" "testing"
"time" "time"
"github.com/mitchellh/cli"
"github.com/zclconf/go-cty/cty"
"github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/helper/copy" "github.com/hashicorp/terraform/helper/copy"
"github.com/hashicorp/terraform/providers"
"github.com/hashicorp/terraform/states" "github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli"
) )
func TestPlan(t *testing.T) { func TestPlan(t *testing.T) {
@ -101,8 +104,8 @@ func TestPlan_plan(t *testing.T) {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
} }
if p.RefreshCalled { if p.ReadResourceCalled {
t.Fatal("refresh should not be called") t.Fatal("ReadResource should not have been called")
} }
} }
@ -143,8 +146,8 @@ func TestPlan_destroy(t *testing.T) {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
} }
if !p.RefreshCalled { if !p.ReadResourceCalled {
t.Fatal("refresh should be called") t.Fatal("ReadResource should have been called")
} }
plan := testReadPlan(t, outPath) plan := testReadPlan(t, outPath)
@ -178,15 +181,15 @@ func TestPlan_noState(t *testing.T) {
} }
// Verify that refresh was called // Verify that refresh was called
if p.RefreshCalled { if p.ReadResourceCalled {
t.Fatal("refresh should not be called") t.Fatal("ReadResource should not be called")
} }
// Verify that the provider was called with the existing state // Verify that the provider was called with the existing state
actual := strings.TrimSpace(p.DiffState.String()) actual := p.PlanResourceChangeRequest.PriorState
expected := strings.TrimSpace(testPlanNoStateStr) expected := cty.NullVal(cty.EmptyObject)
if actual != expected { if !expected.RawEquals(actual) {
t.Fatalf("bad:\n\n%s", actual) t.Fatalf("wrong prior state\ngot: %#v\nwant: %#v", actual, expected)
} }
} }
@ -206,8 +209,8 @@ func TestPlan_outPath(t *testing.T) {
}, },
} }
p.DiffReturn = &terraform.InstanceDiff{ p.PlanResourceChangeResponse = providers.PlanResourceChangeResponse{
Destroy: true, PlannedState: cty.NullVal(cty.EmptyObject),
} }
args := []string{ args := []string{
@ -334,7 +337,7 @@ func TestPlan_outBackend(t *testing.T) {
} }
} }
func TestPlan_refresh(t *testing.T) { func TestPlan_refreshFalse(t *testing.T) {
tmp, cwd := testCwd(t) tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd) defer testFixCwd(t, tmp, cwd)
@ -355,8 +358,8 @@ func TestPlan_refresh(t *testing.T) {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
} }
if p.RefreshCalled { if p.ReadResourceCalled {
t.Fatal("refresh should not be called") t.Fatal("ReadResource should not have been called")
} }
} }
@ -382,10 +385,12 @@ func TestPlan_state(t *testing.T) {
} }
// Verify that the provider was called with the existing state // Verify that the provider was called with the existing state
actual := strings.TrimSpace(p.DiffState.String()) actual := p.PlanResourceChangeRequest.PriorState
expected := strings.TrimSpace(testPlanStateStr) expected := cty.ObjectVal(map[string]cty.Value{
if actual != expected { "id": cty.StringVal("bar"),
t.Fatalf("bad:\n\n%s", actual) })
if !expected.RawEquals(actual) {
t.Fatalf("wrong prior state\ngot: %#v\nwant: %#v", actual, expected)
} }
} }
@ -421,10 +426,12 @@ func TestPlan_stateDefault(t *testing.T) {
} }
// Verify that the provider was called with the existing state // Verify that the provider was called with the existing state
actual := strings.TrimSpace(p.DiffState.String()) actual := p.PlanResourceChangeRequest.PriorState
expected := strings.TrimSpace(testPlanStateDefaultStr) expected := cty.ObjectVal(map[string]cty.Value{
if actual != expected { "id": cty.StringVal("bar"),
t.Fatalf("bad:\n\n%s", actual) })
if !expected.RawEquals(actual) {
t.Fatalf("wrong prior state\ngot: %#v\nwant: %#v", actual, expected)
} }
} }