Beispiel #1
0
func TestGET(t *testing.T) {
	handler := http.HandlerFunc(hello)
	req := mockhttp.NewRequest("GET", "http://foo.example.com/bar", nil)
	req.Header.Set("Content-Type", "text/plain; charset=utf-8")
	respw := mockhttp.NewResponseWriter()
	handler.ServeHTTP(respw, req)
	want_hdr := make(http.Header)
	want_hdr.Add("Content-Type", "text/plain; charset=utf-8")
	respw.Check(t, http.StatusOK, want_hdr, "Hello, world.\n")
}
Beispiel #2
0
func TestPUT(t *testing.T) {
	handler := http.HandlerFunc(hello)
	body := strings.NewReader(`foo`)
	req := mockhttp.NewRequest("PUT", "http://foo.example.com/bar", body)
	req.Header.Set("Content-Type", "text/plain; charset=utf-8")
	respw := mockhttp.NewResponseWriter()
	handler.ServeHTTP(respw, req)
	want_hdr := make(http.Header)
	want_hdr.Add("Content-Type", "text/plain; charset=utf-8")
	want_hdr.Add("Allow", "GET")
	respw.Check(t, http.StatusMethodNotAllowed, want_hdr, "Only GET supported.\n")
}