mirror of
https://github.com/labstack/echo.git
synced 2025-11-29 22:48:07 +02:00
Added JSONP API in Context
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
committed by
Vishal Rana
parent
96e5761b75
commit
9257875cb7
@@ -11,8 +11,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"encoding/xml"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/url"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -94,7 +95,19 @@ func TestContext(t *testing.T) {
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Equal(t, ApplicationJSONCharsetUTF8, rec.Header().Get(ContentType))
|
||||
assert.Equal(t, userJSON, strings.TrimSpace(rec.Body.String()))
|
||||
assert.Equal(t, userJSON+"\n", rec.Body.String())
|
||||
}
|
||||
|
||||
// JSONP
|
||||
req.Header.Set(Accept, ApplicationJavaScript)
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec), New())
|
||||
callback := "callback"
|
||||
err = c.JSONP(http.StatusOK, callback, user{"1", "Joe"})
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Equal(t, ApplicationJavaScriptCharsetUTF8, rec.Header().Get(ContentType))
|
||||
assert.Equal(t, callback+"("+userJSON+"\n);", rec.Body.String())
|
||||
}
|
||||
|
||||
// XML
|
||||
|
||||
Reference in New Issue
Block a user