terraform: test to ensure data sources work on Apply operation

It appears data sources have always been coded to work during apply, as
can be verified with this test (no impl. changes were necessary to make
it pass).

This test should be added to ensure our apply graph always works with
data sources as well.
This commit is contained in:
Mitchell Hashimoto 2016-10-20 21:53:35 -07:00
parent 293e214e3e
commit 1d27e554a5
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 42 additions and 4 deletions

View File

@ -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) { func TestContext2Apply_destroyData(t *testing.T) {
m := testModule(t, "apply-destroy-data-resource") m := testModule(t, "apply-destroy-data-resource")
p := testProvider("null") p := testProvider("null")

View File

@ -25,13 +25,13 @@ func TestMain(m *testing.M) {
// Experimental features // Experimental features
xNewApply := flag.Bool("Xnew-apply", false, "Experiment: new apply graph") xNewApply := flag.Bool("Xnew-apply", false, "Experiment: new apply graph")
// Normal features
shadow := flag.Bool("shadow", true, "Enable shadow graph")
flag.Parse() flag.Parse()
// Setup experimental features // Setup experimental features
X_newApply = *xNewApply X_newApply = *xNewApply
if X_newApply {
println("Xnew-apply enabled")
}
if testing.Verbose() { if testing.Verbose() {
// if we're verbose, use the logging requested by TF_LOG // if we're verbose, use the logging requested by TF_LOG
@ -48,7 +48,7 @@ func TestMain(m *testing.M) {
contextTestDeepCopyOnPlan = true contextTestDeepCopyOnPlan = true
// Shadow the new graphs // Shadow the new graphs
contextTestShadow = true contextTestShadow = *shadow
os.Exit(m.Run()) os.Exit(m.Run())
} }
@ -257,6 +257,11 @@ aws_instance.foo:
type = aws_instance type = aws_instance
` `
const testTerraformApplyDataBasicStr = `
data.null_data_source.testing:
ID = yo
`
const testTerraformApplyRefCountStr = ` const testTerraformApplyRefCountStr = `
aws_instance.bar: aws_instance.bar:
ID = foo ID = foo

View File

@ -0,0 +1 @@
data "null_data_source" "testing" {}