Skip to content

Commit

Permalink
Template rendering fails when using an undefined variable (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-vizcaino authored and gulien committed Apr 23, 2018
1 parent 28db184 commit 1997756
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions _tests/broken-template-missing-var.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
foo: {{ .Orbit.missing }}
2 changes: 2 additions & 0 deletions app/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func (g *OrbitGenerator) Execute() (bytes.Buffer, error) {
return data, OrbitError.NewOrbitErrorf("unable to parse the template file %s. Details:\n%s", g.context.TemplateFilePath, err)
}

tmpl.Option("missingkey=error")

orbitData := &orbitData{
Orbit: g.context.Payload,
}
Expand Down
12 changes: 12 additions & 0 deletions app/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ func TestExecute(t *testing.T) {
}
}

func TestExecuteMissingVariableError(t *testing.T) {
dataSourceFilePath, _ := filepath.Abs("../../_tests/data-source.yml")

// case 1: uses a broken data-driven template.
brokenTemplateFilePath, _ := filepath.Abs("../../_tests/broken-template-missing-var.yml")
ctx, _ := context.NewOrbitContext(brokenTemplateFilePath, "Values,"+dataSourceFilePath)
g := NewOrbitGenerator(ctx)
if _, err := g.Execute(); err == nil {
t.Errorf("OrbitGenerator should not have been able to render the data-driven template %s", brokenTemplateFilePath)
}
}

// Tests if flushing from raw data source works as expected.
func TestFlushFromRawDataSource(t *testing.T) {
templateFilePath, _ := filepath.Abs("../../_tests/template-raw.yml")
Expand Down

0 comments on commit 1997756

Please sign in to comment.