(t *testing.T)
| 1833 | } |
| 1834 | |
| 1835 | func TestContextAbortWithStatusJSON(t *testing.T) { |
| 1836 | w := httptest.NewRecorder() |
| 1837 | c, _ := CreateTestContext(w) |
| 1838 | c.index = 4 |
| 1839 | |
| 1840 | in := new(testJSONAbortMsg) |
| 1841 | in.Bar = "barValue" |
| 1842 | in.Foo = "fooValue" |
| 1843 | |
| 1844 | c.AbortWithStatusJSON(http.StatusUnsupportedMediaType, in) |
| 1845 | |
| 1846 | assert.Equal(t, abortIndex, c.index) |
| 1847 | assert.Equal(t, http.StatusUnsupportedMediaType, c.Writer.Status()) |
| 1848 | assert.Equal(t, http.StatusUnsupportedMediaType, w.Code) |
| 1849 | assert.True(t, c.IsAborted()) |
| 1850 | |
| 1851 | contentType := w.Header().Get("Content-Type") |
| 1852 | assert.Equal(t, "application/json; charset=utf-8", contentType) |
| 1853 | |
| 1854 | buf := new(bytes.Buffer) |
| 1855 | _, err := buf.ReadFrom(w.Body) |
| 1856 | require.NoError(t, err) |
| 1857 | jsonStringBody := buf.String() |
| 1858 | assert.JSONEq(t, "{\"foo\":\"fooValue\",\"bar\":\"barValue\"}", jsonStringBody) |
| 1859 | } |
| 1860 | |
| 1861 | func TestContextAbortWithStatusPureJSON(t *testing.T) { |
| 1862 | w := httptest.NewRecorder() |
nothing calls this directly
no test coverage detected