(t *testing.T)
| 379 | } |
| 380 | |
| 381 | func TestRemoteAddr(t *testing.T) { |
| 382 | var addr string |
| 383 | http.HandleFunc("/remote_addr", func(w http.ResponseWriter, r *http.Request) { |
| 384 | addr = r.RemoteAddr |
| 385 | }) |
| 386 | |
| 387 | testCases := []struct { |
| 388 | headers http.Header |
| 389 | addr string |
| 390 | }{ |
| 391 | {http.Header{"X-Appengine-User-Ip": []string{"10.5.2.1"}}, "10.5.2.1:80"}, |
| 392 | {http.Header{"X-Appengine-Remote-Addr": []string{"1.2.3.4"}}, "1.2.3.4:80"}, |
| 393 | {http.Header{"X-Appengine-Remote-Addr": []string{"1.2.3.4:8080"}}, "1.2.3.4:8080"}, |
| 394 | { |
| 395 | http.Header{"X-Appengine-Remote-Addr": []string{"2401:fa00:9:1:7646:a0ff:fe90:ca66"}}, |
| 396 | "[2401:fa00:9:1:7646:a0ff:fe90:ca66]:80", |
| 397 | }, |
| 398 | { |
| 399 | http.Header{"X-Appengine-Remote-Addr": []string{"[::1]:http"}}, |
| 400 | "[::1]:http", |
| 401 | }, |
| 402 | {http.Header{}, "127.0.0.1:80"}, |
| 403 | } |
| 404 | |
| 405 | for _, tc := range testCases { |
| 406 | r := &http.Request{ |
| 407 | Method: "GET", |
| 408 | URL: &url.URL{Scheme: "http", Path: "/remote_addr"}, |
| 409 | Header: tc.headers, |
| 410 | Body: ioutil.NopCloser(bytes.NewReader(nil)), |
| 411 | } |
| 412 | Middleware(http.DefaultServeMux).ServeHTTP(httptest.NewRecorder(), r) |
| 413 | if addr != tc.addr { |
| 414 | t.Errorf("Header %v, got %q, want %q", tc.headers, addr, tc.addr) |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | func TestPanickingHandler(t *testing.T) { |
| 420 | http.HandleFunc("/panic", func(http.ResponseWriter, *http.Request) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…