diff options
author | Vincent Ambo <tazjin@gmail.com> | 2017-04-04T09·02+0200 |
---|---|---|
committer | Vincent Ambo <tazjin@gmail.com> | 2017-04-04T09·05+0200 |
commit | 3b0f41e71d8ff2763ee827d17034b5d929d0c7ff (patch) | |
tree | 637f1028a3831a409cb98682edc00c477574d66e /templater/templater_test.go | |
parent | 45aee8257fd5bb947cb127cd645d8ab571a15379 (diff) |
feat templater: Fail if values are missing
Golang's template package now has an option for failing if template variables are missing: https://golang.org/pkg/text/template/#Template.Option This updates the templater code to make use of that option and return the errors encountered during templating. This fixes #1
Diffstat (limited to 'templater/templater_test.go')
-rw-r--r-- | templater/templater_test.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/templater/templater_test.go b/templater/templater_test.go index b262787ae9ba..4aeee254d1c2 100644 --- a/templater/templater_test.go +++ b/templater/templater_test.go @@ -3,6 +3,7 @@ package templater import ( "github.com/tazjin/kontemplate/context" "reflect" + "strings" "testing" ) @@ -136,3 +137,19 @@ func TestApplyLimitsExcludeIncludePrecedence(t *testing.T) { t.Fail() } } + +func TestFailOnMissingKeys(t *testing.T) { + ctx := context.Context{} + resourceSet := context.ResourceSet{} + + _, err := templateFile(&ctx, &resourceSet, "testdata/test-template.txt") + + if err == nil { + t.Errorf("Template with missing keys should have failed.\n") + t.Fail() + } + + if !strings.Contains(err.Error(), "map has no entry for key \"testName\"") { + t.Errorf("Templating failed with unexpected error: %v\n", err) + } +} |