Make sure that a Context.diff is never nil

The context and diff passed along during a walk, and the diff is assumed
to be valid.
This commit is contained in:
James Bardin 2016-12-02 10:53:29 -05:00
parent 08a56304bb
commit 6a8df0cbe2
2 changed files with 49 additions and 1 deletions

View File

@ -162,13 +162,18 @@ func NewContext(opts *ContextOpts) (*Context, error) {
}
}
diff := opts.Diff
if diff == nil {
diff = &Diff{}
}
return &Context{
components: &basicComponentFactory{
providers: opts.Providers,
provisioners: opts.Provisioners,
},
destroy: opts.Destroy,
diff: opts.Diff,
diff: diff,
hooks: hooks,
module: opts.Module,
shadow: opts.Shadow,

View File

@ -849,3 +849,46 @@ func TestContext2Validate_interpolateMap(t *testing.T) {
t.Fatal("err:", e)
}
}
// Manually validate using the new PlanGraphBuilder
func TestContext2Validate_PlanGraphBuilder(t *testing.T) {
m := testModule(t, "apply-vars")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
c := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Variables: map[string]interface{}{
"foo": "us-west-2",
"test_list": []interface{}{"Hello", "World"},
"test_map": map[string]interface{}{
"Hello": "World",
"Foo": "Bar",
"Baz": "Foo",
},
"amis": []map[string]interface{}{
map[string]interface{}{
"us-east-1": "override",
},
},
},
})
graph, err := (&PlanGraphBuilder{
Module: c.module,
State: NewState(),
Providers: c.components.ResourceProviders(),
Targets: c.targets,
}).Build(RootModulePath)
walker, err := c.walk(graph, graph, walkValidate)
if err != nil {
t.Fatal(err)
}
if len(walker.ValidationErrors) > 0 {
t.Fatal(walker.ValidationErrors)
}
}