mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 13:02:14 +08:00
Merge 2dbfde74be37ae01ec338a9d2c45d7b22239b451 into 28b9ff9e3495dabeaea2da86c100effbf1a68346
This commit is contained in:
commit
27e5d015e3
@ -69,6 +69,15 @@ type Context struct {
|
|||||||
index int8
|
index int8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/************************************/
|
||||||
|
/*********** TEST HELPERS ***********/
|
||||||
|
/************************************/
|
||||||
|
|
||||||
|
func CreateContext(w http.ResponseWriter, req *http.Request) *Context {
|
||||||
|
engine := New()
|
||||||
|
return engine.createContext(w, req, nil, nil)
|
||||||
|
}
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
/********** ROUTES GROUPING *********/
|
/********** ROUTES GROUPING *********/
|
||||||
/************************************/
|
/************************************/
|
||||||
|
@ -440,3 +440,23 @@ func TestBindingJSONMalformed(t *testing.T) {
|
|||||||
t.Errorf("Content-Type should not be application/json, was %s", w.HeaderMap.Get("Content-Type"))
|
t.Errorf("Content-Type should not be application/json, was %s", w.HeaderMap.Get("Content-Type"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateContext(t *testing.T) {
|
||||||
|
req, _ := http.NewRequest("GET", "/", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
c := CreateContext(w, req)
|
||||||
|
c.JSON(200, H{"foo": "bar"})
|
||||||
|
|
||||||
|
if w.Code != 200 {
|
||||||
|
t.Errorf("Response code should be Ok, was: %s", w.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.HeaderMap.Get("Content-Type") != "application/json" {
|
||||||
|
t.Errorf("Content-Type should be application/json, was %s", w.HeaderMap.Get("Content-Type"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.Body.String() != "{\"foo\":\"bar\"}\n" {
|
||||||
|
t.Errorf("Response should be {\"foo\":\"bar\"}, was: %s", w.Body.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user