mirror of
https://github.com/kevin-DL/football_info_api.git
synced 2026-01-21 06:05:01 +00:00
Initial commit
This commit is contained in:
28
general/testing.go
Normal file
28
general/testing.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user