| 130 | } |
| 131 | |
| 132 | func TestDebuggerHandle(t *testing.T) { |
| 133 | mux := http.NewServeMux() |
| 134 | dbg := Debugger(mux) |
| 135 | dbg.Handle("check", "Consistency check", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 136 | fmt.Fprintf(w, "Test output %v", r.RemoteAddr) |
| 137 | })) |
| 138 | |
| 139 | code, body := get(mux, "/debug/", tsIP) |
| 140 | if code != 200 { |
| 141 | t.Fatalf("debug access failed, got %v", code) |
| 142 | } |
| 143 | for _, want := range []string{"/debug/check", "Consistency check"} { |
| 144 | if !strings.Contains(body, want) { |
| 145 | t.Errorf("want %q in output, not found", want) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | code, _ = get(mux, "/debug/check", pubIP) |
| 150 | if code != 403 { |
| 151 | t.Fatal("/debug/check should be protected, but isn't") |
| 152 | } |
| 153 | |
| 154 | code, body = get(mux, "/debug/check", tsIP) |
| 155 | if code != 200 { |
| 156 | t.Fatal("/debug/check denied debug access") |
| 157 | } |
| 158 | want := "Test output " + tsIP |
| 159 | if !strings.Contains(body, want) { |
| 160 | t.Errorf("want %q in output, not found", want) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | func ExampleDebugHandler_Handle() { |
| 165 | mux := http.NewServeMux() |