Initial commit

This commit is contained in:
2023-07-02 15:26:53 +01:00
committed by GitHub
commit 16ca35eb45
42 changed files with 4536 additions and 0 deletions

28
general/testing.go Normal file
View 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)
}
}