| 890 | } |
| 891 | |
| 892 | func TestRenderStaticErrorPage(t *testing.T) { |
| 893 | t.Parallel() |
| 894 | |
| 895 | d := site.ErrorPageData{ |
| 896 | Status: http.StatusBadGateway, |
| 897 | Title: "Bad Gateway 1234", |
| 898 | Description: "shout out colin", |
| 899 | Actions: []site.Action{ |
| 900 | { |
| 901 | Text: "Retry", |
| 902 | }, |
| 903 | { |
| 904 | URL: "https://example.com", |
| 905 | Text: "Back to site", |
| 906 | }, |
| 907 | }, |
| 908 | } |
| 909 | |
| 910 | rw := httptest.NewRecorder() |
| 911 | r := httptest.NewRequest("GET", "/", nil) |
| 912 | site.RenderStaticErrorPage(rw, r, d) |
| 913 | |
| 914 | resp := rw.Result() |
| 915 | defer resp.Body.Close() |
| 916 | require.Equal(t, d.Status, resp.StatusCode) |
| 917 | require.Contains(t, resp.Header.Get("Content-Type"), "text/html") |
| 918 | |
| 919 | body, err := io.ReadAll(resp.Body) |
| 920 | require.NoError(t, err) |
| 921 | bodyStr := string(body) |
| 922 | require.Contains(t, bodyStr, strconv.Itoa(d.Status)) |
| 923 | require.Contains(t, bodyStr, d.Title) |
| 924 | require.Contains(t, bodyStr, d.Description) |
| 925 | require.Contains(t, bodyStr, "Retry") |
| 926 | require.Contains(t, bodyStr, "https://example.com") |
| 927 | } |
| 928 | |
| 929 | func TestRenderStaticErrorPageNoStatus(t *testing.T) { |
| 930 | t.Parallel() |