| 1 | package home |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "net/http/httptest" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // TestIndex asserts the one page this skeleton serves answers 200 with |
| 10 | // HTML — the placeholder content itself is not asserted here so this |
| 11 | // test does not need updating every time the wording changes. |
| 12 | func TestIndex(t *testing.T) { |
| 13 | app := newTestApp(t) |
| 14 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 15 | req.Host = directoryHost |
| 16 | rec := httptest.NewRecorder() |
| 17 | app.Router().ServeHTTP(rec, req) |
| 18 | if rec.Code != http.StatusOK { |
| 19 | t.Fatalf("GET / = %d, want 200", rec.Code) |
| 20 | } |
| 21 | if ct := rec.Header().Get("Content-Type"); ct == "" { |
| 22 | t.Fatalf("GET / Content-Type is empty") |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | // TestHealthz exercises App.Router()'s own /healthz in isolation via |
| 27 | // httptest — it does NOT prove what a deployed instance answers. In |
| 28 | // production rastrillo.Serve's outer mux registers its own GET /healthz |
| 29 | // ahead of this one and wins (see the comment on Router in app.go); this |
| 30 | // test only proves the app's router itself is wired and reachable. |
| 31 | func TestHealthz(t *testing.T) { |
| 32 | app := newTestApp(t) |
| 33 | req := httptest.NewRequest(http.MethodGet, "/healthz", nil) |
| 34 | req.Host = directoryHost |
| 35 | rec := httptest.NewRecorder() |
| 36 | app.Router().ServeHTTP(rec, req) |
| 37 | if rec.Code != http.StatusOK { |
| 38 | t.Fatalf("healthz = %d, want 200", rec.Code) |
| 39 | } |
| 40 | } |
| 41 | |