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:
parent
293e214e3e
commit
1d27e554a5
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
data "null_data_source" "testing" {}
|
Loading…
Reference in New Issue