| 62 | ) |
| 63 | |
| 64 | func TestDebuggerKV(t *testing.T) { |
| 65 | mux := http.NewServeMux() |
| 66 | dbg := Debugger(mux) |
| 67 | dbg.KV("Donuts", 42) |
| 68 | dbg.KV("Secret code", "hunter2") |
| 69 | val := "red" |
| 70 | dbg.KVFunc("Condition", func() any { return val }) |
| 71 | |
| 72 | code, _ := get(mux, "/debug/", pubIP) |
| 73 | if code != 403 { |
| 74 | t.Fatalf("debug access wasn't denied, got %v", code) |
| 75 | } |
| 76 | |
| 77 | code, body := get(mux, "/debug/", tsIP) |
| 78 | if code != 200 { |
| 79 | t.Fatalf("debug access failed, got %v", code) |
| 80 | } |
| 81 | for _, want := range []string{"Donuts", "42", "Secret code", "hunter2", "Condition", "red"} { |
| 82 | if !strings.Contains(body, want) { |
| 83 | t.Errorf("want %q in output, not found", want) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | val = "green" |
| 88 | code, body = get(mux, "/debug/", tsIP) |
| 89 | if code != 200 { |
| 90 | t.Fatalf("debug access failed, got %v", code) |
| 91 | } |
| 92 | for _, want := range []string{"Condition", "green"} { |
| 93 | if !strings.Contains(body, want) { |
| 94 | t.Errorf("want %q in output, not found", want) |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | func TestDebuggerURL(t *testing.T) { |
| 100 | mux := http.NewServeMux() |