Documentation
¶
Overview ¶
Package testing provides test utilities for the API package.
Index ¶
- func AssertContentType(t *testing.T, resp *http.Response, expectedType string)
- func AssertJSON(t *testing.T, resp *http.Response, v interface{})
- func AssertJSONError(t *testing.T, resp *http.Response, expectedMessage string)
- func AssertStatus(t *testing.T, resp *http.Response, expectedCode int)
- func DecodeJSON(t *testing.T, resp *http.Response, v interface{})
- func MakeRequest(t *testing.T, client *http.Client, baseURL, method, path string, ...) *http.Response
- func MakeRequestWithContext(ctx context.Context, t *testing.T, client *http.Client, ...) *http.Response
- func ReadBody(t *testing.T, resp *http.Response) string
- type ErrorResponse
- type TestServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertContentType ¶
AssertContentType asserts that the response has the expected content type.
func AssertJSON ¶
AssertJSON unmarshals the response body into the given value and asserts no error.
func AssertJSONError ¶
AssertJSONError asserts that the response is a JSON error with the expected message.
func AssertStatus ¶
AssertStatus asserts that the response has the expected status code.
func DecodeJSON ¶
DecodeJSON reads the response body and unmarshals it into v.
func MakeRequest ¶
func MakeRequest(t *testing.T, client *http.Client, baseURL, method, path string, body interface{}) *http.Response
MakeRequest makes an HTTP request and returns the response.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
Details map[string]string `json:"details,omitempty"`
}
ErrorResponse represents a standard error response for assertions.
type TestServer ¶
TestServer wraps httptest.Server with additional testing utilities.
func NewTestServer ¶
func NewTestServer(t *testing.T, router chi.Router) *TestServer
NewTestServer creates a new test server with the given router.
func (*TestServer) Client ¶
func (ts *TestServer) Client() *http.Client
Client returns an HTTP client configured for the test server.
func (*TestServer) MakeRequest ¶
func (ts *TestServer) MakeRequest(method, path string, body interface{}) *http.Response
MakeRequest makes an HTTP request to the test server.
func (*TestServer) MakeRequestWithContext ¶
func (ts *TestServer) MakeRequestWithContext(ctx context.Context, method, path string, body interface{}) *http.Response
MakeRequestWithContext makes an HTTP request with context to the test server.
func (*TestServer) URL ¶
func (ts *TestServer) URL() string
URL returns the base URL of the test server.