mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
improve error reporting for bad templates
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user