Skip to content

Commit

Permalink
core: test that data sources are read during refresh
Browse files Browse the repository at this point in the history
Data sources with non-computed configurations should be read during the
refresh walk. This test ensures that this remains true.
  • Loading branch information
apparentlymart authored and cristicalin committed May 24, 2016
1 parent 30e9a62 commit 211a41a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
70 changes: 70 additions & 0 deletions terraform/context_refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions terraform/test-fixtures/refresh-data-resource-basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "null_data_source" "testing" {
inputs = {
test = "yes"
}
}

0 comments on commit 211a41a

Please sign in to comment.