(t *testing.T)
| 1290 | } |
| 1291 | |
| 1292 | func TestSingleHandler(t *testing.T) { |
| 1293 | h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1294 | name := URLParam(r, "name") |
| 1295 | w.Write([]byte("hi " + name)) |
| 1296 | }) |
| 1297 | |
| 1298 | r, _ := http.NewRequest("GET", "/", nil) |
| 1299 | rctx := NewRouteContext() |
| 1300 | r = r.WithContext(context.WithValue(r.Context(), RouteCtxKey, rctx)) |
| 1301 | rctx.URLParams.Add("name", "joe") |
| 1302 | |
| 1303 | w := httptest.NewRecorder() |
| 1304 | h.ServeHTTP(w, r) |
| 1305 | |
| 1306 | body := w.Body.String() |
| 1307 | expected := "hi joe" |
| 1308 | if body != expected { |
| 1309 | t.Fatalf("expected:%s got:%s", expected, body) |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | // TODO: a Router wrapper test.. |
| 1314 | // |
nothing calls this directly
no test coverage detected