feat ctx: Let sub-resource-sets inherit vars from parent
Users of kontemplate may expect variables defined on the parent resource to be inherited by children. This implements that functionality. Values defined twice are overwritten by the child's definition. Fixes #20
This commit is contained in:
parent
f81fe551bc
commit
0147c3e13e
4 changed files with 81 additions and 0 deletions
|
|
@ -81,3 +81,62 @@ func TestLoadContextWithResourceSetCollections(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSubresourceVariableInheritance(t *testing.T) {
|
||||
ctx, err := LoadContextFromFile("testdata/parent-variables.yaml")
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
expected := Context{
|
||||
Name: "k8s.prod.mydomain.com",
|
||||
ResourceSets: []ResourceSet{
|
||||
{
|
||||
Name: "parent/child",
|
||||
Values: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"bar": "baz",
|
||||
},
|
||||
Include: nil,
|
||||
Parent: "parent",
|
||||
},
|
||||
},
|
||||
BaseDir: "testdata",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(*ctx, expected) {
|
||||
t.Error("Loaded and expected context did not match")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubresourceVariableInheritanceOverride(t *testing.T) {
|
||||
ctx, err := LoadContextFromFile("testdata/parent-variable-override.yaml")
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
expected := Context{
|
||||
Name: "k8s.prod.mydomain.com",
|
||||
ResourceSets: []ResourceSet{
|
||||
{
|
||||
Name: "parent/child",
|
||||
Values: map[string]interface{}{
|
||||
"foo": "newvalue",
|
||||
},
|
||||
Include: nil,
|
||||
Parent: "parent",
|
||||
},
|
||||
},
|
||||
BaseDir: "testdata",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(*ctx, expected) {
|
||||
t.Error("Loaded and expected context did not match")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue