core: test that data sources are read during refresh

Data sources with non-computed configurations should be read during the
refresh walk. This test ensures that this remains true.
This commit is contained in:
Martin Atkins 2016-05-21 08:48:22 -07:00 committed by James Nugent
parent b832fb305b
commit ed9b8f91cf
2 changed files with 75 additions and 0 deletions

View File

@ -570,6 +570,76 @@ func TestContext2Refresh_state(t *testing.T) {
}
}
func TestContext2Refresh_dataState(t *testing.T) {
p := testProvider("null")
m := testModule(t, "refresh-data-resource-basic")
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
// Intentionally no resources since data resources are
// supposed to refresh themselves even if they didn't
// already exist.
Resources: map[string]*ResourceState{},
},
},
}
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"null": testProviderFuncFixed(p),
},
State: state,
})
p.ReadDataDiffFn = nil
p.ReadDataDiffReturn = &InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"inputs.#": {
Old: "0",
New: "1",
Type: DiffAttrInput,
},
"inputs.test": {
Old: "",
New: "yes",
Type: DiffAttrInput,
},
"outputs.#": {
Old: "",
New: "",
NewComputed: true,
Type: DiffAttrOutput,
},
},
}
p.ReadDataApplyFn = nil
p.ReadDataApplyReturn = &InstanceState{
ID: "-",
}
s, err := ctx.Refresh()
if err != nil {
t.Fatalf("err: %s", err)
}
if !p.ReadDataDiffCalled {
t.Fatal("ReadDataDiff should have been called")
}
if !p.ReadDataApplyCalled {
t.Fatal("ReadDataApply should have been called")
}
mod := s.RootModule()
if got := mod.Resources["data.null_data_source.testing"].Primary.ID; got != "-" {
t.Fatalf("resource id is %q; want %s", got, "-")
}
if !reflect.DeepEqual(mod.Resources["data.null_data_source.testing"].Primary, p.ReadDataApplyReturn) {
t.Fatalf("bad: %#v", mod.Resources)
}
}
func TestContext2Refresh_tainted(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "refresh-basic")

View File

@ -0,0 +1,5 @@
data "null_data_source" "testing" {
inputs = {
test = "yes"
}
}