feat(context): allow explicit variables to be defined as argument
These changes allows variables to be defined when executing `kontemplate` via one or more `--variable` arguments. With this in place one can either define new variables or override existing variables loaded from a file: ``` $ kontemplate apply --variable version=v1.0 example/fancy-app.yaml ``` This avoids the need to write variables into a temporary file that is only needed to provide "external variables" into resource sets. Closes https://github.com/tazjin/kontemplate/issues/122
This commit is contained in:
parent
09869cf8fc
commit
5cf9d53e80
3 changed files with 49 additions and 0 deletions
|
|
@ -280,3 +280,25 @@ func TestExplicitSubresourcePathLoading(t *testing.T) {
|
|||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetVariablesFromArguments(t *testing.T) {
|
||||
vars := []string{"version=some-service-version"}
|
||||
ctx, _ := LoadContextFromFile("testdata/default-loading.yaml")
|
||||
|
||||
if err := ctx.SetVariablesFromArguments(&vars); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if version := ctx.Global["version"]; version != "some-service-version" {
|
||||
t.Errorf(`Expected variable "version" to have value "some-service-version" but was "%s"`, version)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetInvalidVariablesFromArguments(t *testing.T) {
|
||||
vars := []string{"version: some-service-version"}
|
||||
ctx, _ := LoadContextFromFile("testdata/default-loading.yaml")
|
||||
|
||||
if err := ctx.SetVariablesFromArguments(&vars); err == nil {
|
||||
t.Error("Expected invalid variable to return an error")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue