mirror of
https://github.com/kevin-DL/football_info_api.git
synced 2026-01-11 18:14:28 +00:00
29 lines
739 B
Go
29 lines
739 B
Go
package general
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
// code based on https://go-chi.io/#/pages/testing
|
|
|
|
// ExecuteRequest creates a new ResponseRecorder
|
|
// then executes the request by calling ServeHTTP in the router
|
|
// after which the handler writes the response to the response recorder
|
|
// which we can then inspect.
|
|
func ExecuteRequest(req *http.Request, s *Server) *httptest.ResponseRecorder {
|
|
rr := httptest.NewRecorder()
|
|
s.Router.ServeHTTP(rr, req)
|
|
|
|
return rr
|
|
}
|
|
|
|
// CheckResponseCode is a simple utility to check the response code
|
|
// of the response
|
|
func CheckResponseCode(t *testing.T, expected, actual int) {
|
|
if expected != actual {
|
|
t.Errorf("Expected response code %d. Got %d\n", expected, actual)
|
|
}
|
|
}
|