(t *testing.T)
| 26 | ) |
| 27 | |
| 28 | func TestStaticResponseHandler(t *testing.T) { |
| 29 | r := fakeRequest() |
| 30 | w := httptest.NewRecorder() |
| 31 | |
| 32 | s := StaticResponse{ |
| 33 | StatusCode: WeakString(strconv.Itoa(http.StatusNotFound)), |
| 34 | Headers: http.Header{ |
| 35 | "X-Test": []string{"Testing"}, |
| 36 | }, |
| 37 | Body: "Text", |
| 38 | Close: true, |
| 39 | } |
| 40 | |
| 41 | err := s.ServeHTTP(w, r, nil) |
| 42 | if err != nil { |
| 43 | t.Errorf("did not expect an error, but got: %v", err) |
| 44 | } |
| 45 | |
| 46 | resp := w.Result() |
| 47 | respBody, _ := io.ReadAll(resp.Body) |
| 48 | |
| 49 | if resp.StatusCode != http.StatusNotFound { |
| 50 | t.Errorf("expected status %d but got %d", http.StatusNotFound, resp.StatusCode) |
| 51 | } |
| 52 | if resp.Header.Get("X-Test") != "Testing" { |
| 53 | t.Errorf("expected x-test header to be 'testing' but was '%s'", resp.Header.Get("X-Test")) |
| 54 | } |
| 55 | if string(respBody) != "Text" { |
| 56 | t.Errorf("expected body to be 'test' but was '%s'", respBody) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | func fakeRequest() *http.Request { |
| 61 | r, _ := http.NewRequest("GET", "/", nil) |
nothing calls this directly
no test coverage detected