callAdminUpstreams fires a GET against handleUpstreams and returns the decoded response body.
(t *testing.T)
| 58 | // callAdminUpstreams fires a GET against handleUpstreams and returns the |
| 59 | // decoded response body. |
| 60 | func callAdminUpstreams(t *testing.T) []upstreamStatus { |
| 61 | t.Helper() |
| 62 | req := httptest.NewRequest(http.MethodGet, "/reverse_proxy/upstreams", nil) |
| 63 | w := httptest.NewRecorder() |
| 64 | |
| 65 | handler := adminUpstreams{} |
| 66 | if err := handler.handleUpstreams(w, req); err != nil { |
| 67 | t.Fatalf("handleUpstreams returned unexpected error: %v", err) |
| 68 | } |
| 69 | if w.Code != http.StatusOK { |
| 70 | t.Fatalf("expected 200, got %d", w.Code) |
| 71 | } |
| 72 | if ct := w.Header().Get("Content-Type"); ct != "application/json" { |
| 73 | t.Fatalf("expected Content-Type application/json, got %q", ct) |
| 74 | } |
| 75 | |
| 76 | var results []upstreamStatus |
| 77 | if err := json.NewDecoder(w.Body).Decode(&results); err != nil { |
| 78 | t.Fatalf("failed to decode response: %v", err) |
| 79 | } |
| 80 | return results |
| 81 | } |
| 82 | |
| 83 | // resultsByAddress indexes a slice of upstreamStatus by address for easier |
| 84 | // lookup in assertions. |
no test coverage detected