mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-12 16:48:19 +08:00
Compare commits
2 Commits
78e4fe63d8
...
1703c6c889
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1703c6c889 | ||
|
|
24013a25ef |
@ -1318,6 +1318,33 @@ func TestContextRenderNoContentXML(t *testing.T) {
|
||||
assert.Equal(t, "application/xml; charset=utf-8", w.Header().Get("Content-Type"))
|
||||
}
|
||||
|
||||
// TestContextRenderPDF tests that the response is serialized as PDF
|
||||
// and Content-Type is set to application/pdf
|
||||
func TestContextRenderPDF(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := CreateTestContext(w)
|
||||
|
||||
data := []byte("%Test pdf content")
|
||||
c.PDF(http.StatusCreated, data)
|
||||
|
||||
assert.Equal(t, http.StatusCreated, w.Code)
|
||||
assert.Equal(t, data, w.Body.Bytes())
|
||||
assert.Equal(t, "application/pdf", w.Header().Get("Content-Type"))
|
||||
}
|
||||
|
||||
// Tests that no PDF is rendered if code is 204
|
||||
func TestContextRenderNoContentPDF(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := CreateTestContext(w)
|
||||
|
||||
data := []byte("%Test pdf content")
|
||||
c.PDF(http.StatusNoContent, data)
|
||||
|
||||
assert.Equal(t, http.StatusNoContent, w.Code)
|
||||
assert.Empty(t, w.Body.Bytes())
|
||||
assert.Equal(t, "application/pdf", w.Header().Get("Content-Type"))
|
||||
}
|
||||
|
||||
// TestContextRenderString tests that the response is returned
|
||||
// with Content-Type set to text/plain
|
||||
func TestContextRenderString(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user