diff options
author | Vincent Ambo <tazjin@gmail.com> | 2018-07-14T19·40+0200 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2018-07-14T21·21+0200 |
commit | df1a9a1625f01478b1ce6a5754363468f4342924 (patch) | |
tree | acec7b145a8ffc30adce5221290a4ab509a311c9 /templater | |
parent | ab059ad41c7195e5c4a3f456b7f590d881884dcf (diff) |
test(templater): Add a test for the `default` template function
Diffstat (limited to 'templater')
-rw-r--r-- | templater/templater_test.go | 17 | ||||
-rw-r--r-- | templater/testdata/test-default.txt | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/templater/templater_test.go b/templater/templater_test.go index f6b12c758057..2a9ddaa2bb10 100644 --- a/templater/templater_test.go +++ b/templater/templater_test.go @@ -162,3 +162,20 @@ func TestFailOnMissingKeys(t *testing.T) { t.Errorf("Templating failed with unexpected error: %v\n", err) } } + +func TestDefaultTemplateFunction(t *testing.T) { + ctx := context.Context{} + resourceSet := context.ResourceSet{} + + res, err := templateFile(&ctx, &resourceSet, "testdata/test-default.txt") + + if err != nil { + t.Errorf("Templating with default values should have succeeded.\n") + t.Fail() + } + + if res.Rendered != "defaultValue\n" { + t.Error("Result does not contain expected rendered default value.") + t.Fail() + } +} diff --git a/templater/testdata/test-default.txt b/templater/testdata/test-default.txt new file mode 100644 index 000000000000..4f7997bd69d2 --- /dev/null +++ b/templater/testdata/test-default.txt @@ -0,0 +1 @@ +{{ default "defaultValue" "missingVar" }} |