func makeRequest(t *testing.T, app *forest.App, params *requested, want *wanted) (*http.Response, *forest.Response) { var request *http.Request method := params.method auth := params.auth path := params.path body := params.body if body != nil { request, _ = http.NewRequest(method, path, bytes.NewBuffer(body)) } else { request, _ = http.NewRequest(method, path, nil) } if len(auth) > 0 { request.AddCookie(&http.Cookie{Name: forest.SessionID, Value: auth}) } response := httptest.NewRecorder() app.ServeHTTP(response, request) responseData := new(forest.Response) responseBody, err := ioutil.ReadAll(response.Body) if err != nil { t.Error(err) return nil, responseData } if err := json.Unmarshal(responseBody, responseData); err != nil { t.Errorf("unmarshal error: %v when attempting to read: %s", err, string(responseBody)) return nil, responseData } if response.Code != want.code { t.Errorf("%s %s want: %d (%s) got: %d %s, body: %s", method, path, want.code, http.StatusText(want.code), response.Code, http.StatusText(response.Code), string(responseBody)) return nil, responseData } if responseData.Success != want.success { t.Errorf("%s %s should return success: %t", method, path, want.success) return nil, responseData } return &http.Response{Header: response.Header()}, responseData }