Created
July 20, 2015 11:36
-
-
Save mindscratch/d0196414b684276db046 to your computer and use it in GitHub Desktop.
test code that uses julienschmidt/httprouter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "github.com/julienschmidt/httprouter" | |
import "net/http" | |
func doRequest(method, uri string, body *bytes.Buffer, handle httprouter.Handle) (*httptest.ResponseRecorder, error) { | |
resp := httptest.NewRecorder() | |
req, err := http.NewRequest(method, uri, body) | |
if err != nil { | |
return nil, err | |
} | |
router := httprouter.New() | |
router.Handle(method, uri, handle) | |
router.ServeHTTP(resp, req) | |
return resp, nil | |
} | |
func SomeTest(t *testing.T) { | |
body := bytes.NewBuffferString("hello") | |
handle := SomeHandle() | |
resp, err := doRequest("POST", "/v1/test", body, handle) | |
// check resp.Code, etc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
Typo:
bytes.NewBuffferString
has three f ;-)