MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestServeHTTP

Method TestServeHTTP

server/router_test.go:160–180  ·  view source on GitHub ↗

TestServeHTTP tests ServeHTTP method

()

Source from the content-addressed store, hash-verified

158
159// TestServeHTTP tests ServeHTTP method
160func (s *RouterTestSuite) TestServeHTTP() {
161 handler := func(reqID string, rw server.ResponseWriter, req *http.Request) *server.Error {
162 rw.Header().Set("Custom-Header", "test-value")
163 rw.WriteHeader(http.StatusOK)
164 rw.Write([]byte("success"))
165 return nil
166 }
167
168 s.router.GET("/test", handler)
169
170 req := httptest.NewRequest(http.MethodGet, "/api/test", nil)
171 rw := httptest.NewRecorder()
172
173 s.router.ServeHTTP(rw, req)
174
175 s.Require().Equal(http.StatusOK, rw.Code)
176 s.Require().Equal("success", rw.Body.String())
177 s.Require().Equal("test-value", rw.Header().Get("Custom-Header"))
178 s.Require().Equal(server.DefaultServerName, rw.Header().Get(httpheaders.Server))
179 s.Require().NotEmpty(rw.Header().Get(httpheaders.XRequestID))
180}
181
182// TestRequestID checks request ID generation and validation
183func (s *RouterTestSuite) TestRequestID() {

Callers

nothing calls this directly

Calls 8

WriteHeaderMethod · 0.80
NewRequestMethod · 0.80
ServeHTTPMethod · 0.80
GetMethod · 0.65
SetMethod · 0.45
WriteMethod · 0.45
GETMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected