mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 02:32:17 +08:00
add jsonp test on the context
This commit is contained in:
parent
c5325c190e
commit
db85d1227e
@ -581,6 +581,20 @@ func TestContextRenderJSON(t *testing.T) {
|
|||||||
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests that the response is serialized as JSONP
|
||||||
|
// and Content-Type is set to application/javascript
|
||||||
|
func TestContextRenderJSONP(t *testing.T) {
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
c, _ := CreateTestContext(w)
|
||||||
|
c.Request, _ = http.NewRequest("GET", "http://example.com/?callback=x", nil)
|
||||||
|
|
||||||
|
c.JSONP(201, H{"foo": "bar"})
|
||||||
|
|
||||||
|
assert.Equal(t, 201, w.Code)
|
||||||
|
assert.Equal(t, "x({\"foo\":\"bar\"})", w.Body.String())
|
||||||
|
assert.Equal(t, "application/javascript; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||||
|
}
|
||||||
|
|
||||||
// Tests that no JSON is rendered if code is 204
|
// Tests that no JSON is rendered if code is 204
|
||||||
func TestContextRenderNoContentJSON(t *testing.T) {
|
func TestContextRenderNoContentJSON(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user