func (th TestHandler) testRequest(method string, dest string, body io.Reader, status int) *httptest.ResponseRecorder { // fetching the request router r := RouteHandler.GetHandler(th.Db) // generating a request to test it req, err := http.NewRequest(method, dest, body) assert.Nil(th.T, err, fmt.Sprintf("Could not create new %s %s request", method, dest)) // serving up a single request and recording the response w := httptest.NewRecorder() r.ServeHTTP(w, req) // checking for 500 errors if w.Code == http.StatusInternalServerError { var errResponse Util.ErrorResponse err = json.NewDecoder(w.Body).Decode(&errResponse) assert.Nil(th.T, err, "Could not decode response body") assert.NotNil(th.T, nil, fmt.Sprintf("Response code was 500: %s", errResponse.Error)) return w } // asserting that it worked properly assert.Equal(th.T, status, w.Code, fmt.Sprintf("Response code was not %d", http.StatusOK)) return w }
func main() { log.Info("Starting up") db, err := sqlx.Connect( "postgres", "postgres://postgres@Db/postgres?sslmode=disable", ) if err != nil { log.Fatal(err.Error()) } err = http.ListenAndServe(":80", loggingMiddleware(corsMiddleware(RouteHandler.GetHandler(db)))) if err != nil { log.WithFields(log.Fields{ "err": err, }).Fatal("Could not listen on 80") } }