@@ -36,7 +36,11 @@ type T struct{}
3636
3737func (T) F(context.Context, any) any { return nil }
3838
39- func (T) Headers(response http.ResponseWriter) any { return nil }
39+ func (T) Headers(response http.ResponseWriter) any {
40+ response.Header().Set("x-some-data", "123")
41+ response.WriteHeader(http.StatusNotFound)
42+ return nil
43+ }
4044-- template_test.go --
4145package main
4246
@@ -80,10 +84,19 @@ func Test(t *testing.T) {
8084
8185 mux.ServeHTTP(res, req)
8286
83- if res.WriteHeaderCallCount != 0 {
84- t.Error("unexpected WriteHeader call")
87+ if res.WriteHeaderCallCount != 1 {
88+ t.Errorf("unexpected WriteHeader count: want %d got %d", 1, res.WriteHeaderCallCount)
89+ }
90+ if res.HeaderCallCount != 3 {
91+ t.Errorf("unexpected Header call count: want %d got %d", 3, res.HeaderCallCount)
92+ }
93+ if val := rec.Result().Header.Get("x-some-data"); val != "123" {
94+ t.Errorf("unexpected value for x-some-data: want %q got %q", "123", val)
95+ }
96+ if rec.Result().Header.Get("content-length") == "" {
97+ t.Error("unexpected content-length to be set")
8598 }
86- if res.HeaderCallCount != 0 {
87- t.Error("unexpected HeaderCall call ")
99+ if rec.Result().Header.Get("content-type") == "" {
100+ t.Error("unexpected content-type to be set ")
88101 }
89102}
0 commit comments