Merge 2dbfde74be37ae01ec338a9d2c45d7b22239b451 into 28b9ff9e3495dabeaea2da86c100effbf1a68346

This commit is contained in:
Wael M. Nasreddine 2015-01-02 16:46:37 +00:00
commit 27e5d015e3
2 changed files with 29 additions and 0 deletions

View File

@ -69,6 +69,15 @@ type Context struct {
index int8
}
/************************************/
/*********** TEST HELPERS ***********/
/************************************/
func CreateContext(w http.ResponseWriter, req *http.Request) *Context {
engine := New()
return engine.createContext(w, req, nil, nil)
}
/************************************/
/********** ROUTES GROUPING *********/
/************************************/

View File

@ -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"))
}
}
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())
}
}