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