From 86dd8938c9e86cd3ec1761190cf0a34d8a2cb615 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 16 Sep 2020 16:25:51 -0400 Subject: [PATCH] data sources now show up in the initial plan --- command/e2etest/automation_test.go | 19 +++++++++++++++++-- command/e2etest/primary_test.go | 20 ++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/command/e2etest/automation_test.go b/command/e2etest/automation_test.go index af641a786..9c42ae527 100644 --- a/command/e2etest/automation_test.go +++ b/command/e2etest/automation_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform/e2e" + "github.com/hashicorp/terraform/plans" ) // The tests in this file run through different scenarios recommended in our @@ -72,11 +73,25 @@ func TestPlanApplyInAutomation(t *testing.T) { // stateResources := plan.Changes.Resources diffResources := plan.Changes.Resources - - if len(diffResources) != 1 || diffResources[0].Addr.String() != "null_resource.test" { + if len(diffResources) != 2 { t.Errorf("incorrect number of resources in plan") } + expected := map[string]plans.Action{ + "data.template_file.test": plans.Read, + "null_resource.test": plans.Create, + } + + for _, r := range diffResources { + expectedAction, ok := expected[r.Addr.String()] + if !ok { + t.Fatalf("unexpected change for %q", r.Addr) + } + if r.Action != expectedAction { + t.Fatalf("unexpected action %q for %q", r.Action, r.Addr) + } + } + //// APPLY stdout, stderr, err = tf.Run("apply", "-input=false", "tfplan") if err != nil { diff --git a/command/e2etest/primary_test.go b/command/e2etest/primary_test.go index 46a7c33bf..31aabd2fd 100644 --- a/command/e2etest/primary_test.go +++ b/command/e2etest/primary_test.go @@ -9,6 +9,7 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/hashicorp/terraform/e2e" + "github.com/hashicorp/terraform/plans" "github.com/zclconf/go-cty/cty" ) @@ -71,8 +72,23 @@ func TestPrimarySeparatePlan(t *testing.T) { } diffResources := plan.Changes.Resources - if len(diffResources) != 1 || diffResources[0].Addr.String() != "null_resource.test" { - t.Errorf("incorrect diff in plan; want just null_resource.test to have been rendered, but have:\n%s", spew.Sdump(diffResources)) + if len(diffResources) != 2 { + t.Errorf("incorrect number of resources in plan") + } + + expected := map[string]plans.Action{ + "data.template_file.test": plans.Read, + "null_resource.test": plans.Create, + } + + for _, r := range diffResources { + expectedAction, ok := expected[r.Addr.String()] + if !ok { + t.Fatalf("unexpected change for %q", r.Addr) + } + if r.Action != expectedAction { + t.Fatalf("unexpected action %q for %q", r.Action, r.Addr) + } } //// APPLY