diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 397334bbb..4451db330 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -508,6 +508,38 @@ func TestContext2Apply_destroyComputed(t *testing.T) { } } +func TestContext2Apply_dataBasic(t *testing.T) { + m := testModule(t, "apply-data-basic") + p := testProvider("null") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + p.ReadDataApplyReturn = &InstanceState{ID: "yo"} + + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + }) + + if p, err := ctx.Plan(); err != nil { + t.Fatalf("err: %s", err) + } else { + t.Logf(p.String()) + } + + state, err := ctx.Apply() + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(state.String()) + expected := strings.TrimSpace(testTerraformApplyDataBasicStr) + if actual != expected { + t.Fatalf("bad: \n%s", actual) + } +} + func TestContext2Apply_destroyData(t *testing.T) { m := testModule(t, "apply-destroy-data-resource") p := testProvider("null") diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index ceab1d7fa..f58e3b116 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -25,13 +25,13 @@ func TestMain(m *testing.M) { // Experimental features xNewApply := flag.Bool("Xnew-apply", false, "Experiment: new apply graph") + // Normal features + shadow := flag.Bool("shadow", true, "Enable shadow graph") + flag.Parse() // Setup experimental features X_newApply = *xNewApply - if X_newApply { - println("Xnew-apply enabled") - } if testing.Verbose() { // if we're verbose, use the logging requested by TF_LOG @@ -48,7 +48,7 @@ func TestMain(m *testing.M) { contextTestDeepCopyOnPlan = true // Shadow the new graphs - contextTestShadow = true + contextTestShadow = *shadow os.Exit(m.Run()) } @@ -257,6 +257,11 @@ aws_instance.foo: type = aws_instance ` +const testTerraformApplyDataBasicStr = ` +data.null_data_source.testing: + ID = yo +` + const testTerraformApplyRefCountStr = ` aws_instance.bar: ID = foo diff --git a/terraform/test-fixtures/apply-data-basic/main.tf b/terraform/test-fixtures/apply-data-basic/main.tf new file mode 100644 index 000000000..0c3bd8817 --- /dev/null +++ b/terraform/test-fixtures/apply-data-basic/main.tf @@ -0,0 +1 @@ +data "null_data_source" "testing" {}