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:
parent
08a56304bb
commit
6a8df0cbe2
|
@ -162,13 +162,18 @@ func NewContext(opts *ContextOpts) (*Context, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diff := opts.Diff
|
||||||
|
if diff == nil {
|
||||||
|
diff = &Diff{}
|
||||||
|
}
|
||||||
|
|
||||||
return &Context{
|
return &Context{
|
||||||
components: &basicComponentFactory{
|
components: &basicComponentFactory{
|
||||||
providers: opts.Providers,
|
providers: opts.Providers,
|
||||||
provisioners: opts.Provisioners,
|
provisioners: opts.Provisioners,
|
||||||
},
|
},
|
||||||
destroy: opts.Destroy,
|
destroy: opts.Destroy,
|
||||||
diff: opts.Diff,
|
diff: diff,
|
||||||
hooks: hooks,
|
hooks: hooks,
|
||||||
module: opts.Module,
|
module: opts.Module,
|
||||||
shadow: opts.Shadow,
|
shadow: opts.Shadow,
|
||||||
|
|
|
@ -849,3 +849,46 @@ func TestContext2Validate_interpolateMap(t *testing.T) {
|
||||||
t.Fatal("err:", e)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue