Skip to content

Commit

Permalink
Configure text/template to fail when a value is missed
Browse files Browse the repository at this point in the history
By default the html/template rendered an empty string when a variable is
not passed to the template.Execution. The text/template has a different
behavior. By default it prints `<no value>`. With this configuration now
it errors and tells that a variable is missed

Signed-off-by: Gianluca Arbezzano <[email protected]>
  • Loading branch information
Gianluca Arbezzano committed Jan 15, 2021
1 parent c0a6500 commit df65bc5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
2 changes: 1 addition & 1 deletion workflow/template_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func RenderTemplate(templateID, templateData string, devices []byte) (string, er
return "", err
}

t := template.New("workflow-template")
t := template.New("workflow-template").Option("missingkey=error")
_, err = t.Parse(string(templateData))
if err != nil {
err = errors.Wrapf(err, errTemplateParsing, templateID)
Expand Down
1 change: 0 additions & 1 deletion workflow/template_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ tasks:
{
name: "invalid-hardware-address",
templateData: validTemplate,
skip: "Not sure if this is an expected error or not but this test is not well written",
hwAddress: []byte("{\"invalid_device\":\"08:00:27:00:00:01\"}"),
expectedError: func(t *testing.T, err error) {
if err == nil {
Expand Down

0 comments on commit df65bc5

Please sign in to comment.