|
|
|
|
@ -15,6 +15,7 @@ package web |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"net/http" |
|
|
|
|
"net/http/httptest" |
|
|
|
|
"net/url" |
|
|
|
|
"testing" |
|
|
|
|
"time" |
|
|
|
|
@ -146,3 +147,37 @@ func TestReadyAndHealthy(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDebugHandler(t *testing.T) { |
|
|
|
|
for _, tc := range []struct { |
|
|
|
|
prefix, url string |
|
|
|
|
code int |
|
|
|
|
}{ |
|
|
|
|
{"/", "/debug/pprof/cmdline", 200}, |
|
|
|
|
{"/foo", "/foo/debug/pprof/cmdline", 200}, |
|
|
|
|
|
|
|
|
|
{"/", "/debug/pprof/goroutine", 200}, |
|
|
|
|
{"/foo", "/foo/debug/pprof/goroutine", 200}, |
|
|
|
|
|
|
|
|
|
{"/", "/debug/pprof/foo", 404}, |
|
|
|
|
{"/foo", "/bar/debug/pprof/goroutine", 404}, |
|
|
|
|
} { |
|
|
|
|
opts := &Options{ |
|
|
|
|
RoutePrefix: tc.prefix, |
|
|
|
|
MetricsPath: "/metrics", |
|
|
|
|
} |
|
|
|
|
handler := New(opts) |
|
|
|
|
handler.Ready() |
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder() |
|
|
|
|
req, err := http.NewRequest("GET", tc.url, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("Unexpected error %s", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handler.router.ServeHTTP(w, req) |
|
|
|
|
if w.Code != tc.code { |
|
|
|
|
t.Fatalf("Unexpected status code %d: %s", w.Code, w.Body.String()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|