(t *testing.T)
| 69 | } |
| 70 | |
| 71 | func TestWrap_integration(t *testing.T) { |
| 72 | tests := []struct { |
| 73 | Name string |
| 74 | Handler http.Handler |
| 75 | Hooks Hooks |
| 76 | WantCode int |
| 77 | WantBody []byte |
| 78 | }{ |
| 79 | { |
| 80 | Name: "WriteHeader (no hook)", |
| 81 | Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 82 | w.WriteHeader(http.StatusNotFound) |
| 83 | }), |
| 84 | WantCode: http.StatusNotFound, |
| 85 | }, |
| 86 | { |
| 87 | Name: "WriteHeader", |
| 88 | Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 89 | w.WriteHeader(http.StatusNotFound) |
| 90 | }), |
| 91 | Hooks: Hooks{ |
| 92 | WriteHeader: func(next WriteHeaderFunc) WriteHeaderFunc { |
| 93 | return func(code int) { |
| 94 | if code != http.StatusNotFound { |
| 95 | t.Errorf("got=%d want=%d", code, http.StatusNotFound) |
| 96 | } |
| 97 | next(http.StatusForbidden) |
| 98 | } |
| 99 | }, |
| 100 | }, |
| 101 | WantCode: http.StatusForbidden, |
| 102 | }, |
| 103 | |
| 104 | { |
| 105 | Name: "Write (no hook)", |
| 106 | Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 107 | w.Write([]byte("foo")) |
| 108 | }), |
| 109 | WantCode: http.StatusOK, |
| 110 | WantBody: []byte("foo"), |
| 111 | }, |
| 112 | { |
| 113 | Name: "Write (rewrite hook)", |
| 114 | Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 115 | if n, err := w.Write([]byte("foo")); err != nil { |
| 116 | t.Errorf("got=%s", err) |
| 117 | } else if got, want := n, len("foobar"); got != want { |
| 118 | t.Errorf("got=%d want=%d", got, want) |
| 119 | } |
| 120 | }), |
| 121 | Hooks: Hooks{ |
| 122 | Write: func(next WriteFunc) WriteFunc { |
| 123 | return func(p []byte) (int, error) { |
| 124 | if string(p) != "foo" { |
| 125 | t.Errorf("%s", p) |
| 126 | } |
| 127 | return next([]byte("foobar")) |
| 128 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…