| // NOTE: with no plain-text in the template, template.Execute will not |
| // return an error when http.ResponseWriter.Write does return an error. |
| tmpl = template.Must(template.New("test").Parse("{{.Foo}}")) |
| type errResponseWriter struct { |
| func (*errResponseWriter) Header() http.Header { |
| func (*errResponseWriter) WriteHeader(int) { |
| func (*errResponseWriter) Write(p []byte) (int, error) { |
| return 0, errors.New("error") |
| func TestApplyTemplateToResponseWriter(t *testing.T) { |
| for _, tc := range []struct { |
| rw: &httptest.ResponseRecorder{}, |
| rw: &httptest.ResponseRecorder{}, |
| desc: "ResponseWriter error", |
| rw: &errResponseWriter{}, |
| applyTemplateToResponseWriter(tc.rw, tmpl, tc.data) |
| httpErrors.Do(func(expvar.KeyValue) { |
| if gotVars != tc.expVars { |
| t.Errorf("applyTemplateToResponseWriter(%q): got %d vars, want %d", tc.desc, gotVars, tc.expVars) |