improve error reporting for bad templates

This commit is contained in:
Daniel Smith
2014-12-23 11:21:38 -08:00
parent 6916235513
commit 16c624b2e6
4 changed files with 58 additions and 6 deletions

View File

@@ -290,6 +290,23 @@ func TestTemplateEmitsVersionedObjects(t *testing.T) {
}
}
func TestTemplatePanic(t *testing.T) {
tmpl := `{{and ((index .currentState.info "update-demo").state.running.startedAt) .currentState.info.net.state.running.startedAt}}`
// kind is always blank in memory and set on the wire
printer, err := NewTemplatePrinter([]byte(tmpl), testapi.Version(), api.Scheme)
if err != nil {
t.Fatalf("tmpl fail: %v", err)
}
buffer := &bytes.Buffer{}
err = printer.PrintObj(&api.Pod{}, buffer)
if err == nil {
t.Fatalf("expected that template to crash")
}
if buffer.String() == "" {
t.Errorf("no debugging info was printed")
}
}
func TestPrinters(t *testing.T) {
om := func(name string) api.ObjectMeta { return api.ObjectMeta{Name: name} }
templatePrinter, err := NewTemplatePrinter([]byte("{{.name}}"), testapi.Version(), api.Scheme)