diff --git a/context.go b/context.go index 8fed41de..62677447 100644 --- a/context.go +++ b/context.go @@ -65,6 +65,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 *********/ /************************************/ diff --git a/context_test.go b/context_test.go index 3b3302e8..bf193303 100644 --- a/context_test.go +++ b/context_test.go @@ -436,3 +436,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()) + } +}