testing

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package testing provides test utilities for the API package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContentType

func AssertContentType(t *testing.T, resp *http.Response, expectedType string)

AssertContentType asserts that the response has the expected content type.

func AssertJSON

func AssertJSON(t *testing.T, resp *http.Response, v interface{})

AssertJSON unmarshals the response body into the given value and asserts no error.

func AssertJSONError

func AssertJSONError(t *testing.T, resp *http.Response, expectedMessage string)

AssertJSONError asserts that the response is a JSON error with the expected message.

func AssertStatus

func AssertStatus(t *testing.T, resp *http.Response, expectedCode int)

AssertStatus asserts that the response has the expected status code.

func DecodeJSON

func DecodeJSON(t *testing.T, resp *http.Response, v interface{})

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.

func MakeRequestWithContext

func MakeRequestWithContext(ctx context.Context, t *testing.T, client *http.Client, baseURL, method, path string, body interface{}) *http.Response

MakeRequestWithContext makes an HTTP request with context and returns the response.

func ReadBody

func ReadBody(t *testing.T, resp *http.Response) string

ReadBody reads and returns the response body as a string.

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

type TestServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL