test(context): Introduce an explicit value merging test
Introduces a test which will merge variables defined at every possible
layer together and ensure that the loaded context configuration is as
expected.
The test data provides an actual resource set template that can be
tested locally from a kontemplate source checkout:
kontemplate template context/testdata/merging/context.yaml --var cliVar=cliVar
This commit is contained in:
parent
4a6f087fbf
commit
6d8214bfc8
5 changed files with 51 additions and 0 deletions
|
|
@ -293,3 +293,25 @@ func TestSetInvalidVariablesFromArguments(t *testing.T) {
|
|||
t.Error("Expected invalid variable to return an error")
|
||||
}
|
||||
}
|
||||
|
||||
// This test ensures that variables are merged in the correct order.
|
||||
// Please consult the test data in `testdata/merging`.
|
||||
func TestValueMergePrecedence(t *testing.T) {
|
||||
cliVars:= []string{"cliVar=cliVar"}
|
||||
ctx, _ := LoadContext("testdata/merging/context.yaml", &cliVars)
|
||||
|
||||
expected := map[string]interface{}{
|
||||
"defaultVar": "defaultVar",
|
||||
"importVar": "importVar",
|
||||
"globalVar": "globalVar",
|
||||
"includeVar": "includeVar",
|
||||
"cliVar": "cliVar",
|
||||
}
|
||||
|
||||
result := ctx.ResourceSets[0].Values
|
||||
|
||||
if !reflect.DeepEqual(expected, result) {
|
||||
t.Errorf("Merged values did not match expected result: \n%v", result)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue