Documentation
¶
Overview ¶
Package testutil provides test helpers and assertions for middleware tests.
Index ¶
- func AssertBodyContains(t *testing.T, rec *celeristest.ResponseRecorder, substr string)
- func AssertBodyEmpty(t *testing.T, rec *celeristest.ResponseRecorder)
- func AssertError(t *testing.T, err error)
- func AssertHTTPError(t *testing.T, err error, expectedCode int)
- func AssertHeader(t *testing.T, rec *celeristest.ResponseRecorder, key, expected string)
- func AssertHeaderContains(t *testing.T, rec *celeristest.ResponseRecorder, key, substr string)
- func AssertNoError(t *testing.T, err error)
- func AssertNoHeader(t *testing.T, rec *celeristest.ResponseRecorder, key string)
- func AssertStatus(t *testing.T, rec *celeristest.ResponseRecorder, expected int)
- func RunChain(t *testing.T, chain []celeris.HandlerFunc, method, path string, ...) (*celeristest.ResponseRecorder, error)
- func RunMiddleware(t *testing.T, mw celeris.HandlerFunc, opts ...celeristest.Option) (*celeristest.ResponseRecorder, error)
- func RunMiddlewareWithMethod(t *testing.T, mw celeris.HandlerFunc, method, path string, ...) (*celeristest.ResponseRecorder, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertBodyContains ¶
func AssertBodyContains(t *testing.T, rec *celeristest.ResponseRecorder, substr string)
AssertBodyContains fails the test if the body does not contain substr.
func AssertBodyEmpty ¶
func AssertBodyEmpty(t *testing.T, rec *celeristest.ResponseRecorder)
AssertBodyEmpty fails the test if the body is not empty.
func AssertError ¶
AssertError fails the test if err is nil.
func AssertHTTPError ¶
AssertHTTPError fails the test if err is not an *celeris.HTTPError with the expected code.
func AssertHeader ¶
func AssertHeader(t *testing.T, rec *celeristest.ResponseRecorder, key, expected string)
AssertHeader fails the test if the header value does not match expected.
func AssertHeaderContains ¶
func AssertHeaderContains(t *testing.T, rec *celeristest.ResponseRecorder, key, substr string)
AssertHeaderContains fails the test if no header entry for key contains substr. When multiple entries exist for the same key (e.g., from AddHeader), all entries are checked and the assertion passes if any one contains substr.
func AssertNoError ¶
AssertNoError fails the test if err is not nil.
func AssertNoHeader ¶
func AssertNoHeader(t *testing.T, rec *celeristest.ResponseRecorder, key string)
AssertNoHeader fails the test if any header entry exists for key.
func AssertStatus ¶
func AssertStatus(t *testing.T, rec *celeristest.ResponseRecorder, expected int)
AssertStatus fails the test if the recorder's status code does not match expected.
func RunChain ¶
func RunChain(t *testing.T, chain []celeris.HandlerFunc, method, path string, opts ...celeristest.Option) (*celeristest.ResponseRecorder, error)
RunChain creates a test context with the given handler chain and executes it. The first handler in the chain is called, and each c.Next() progresses through the remaining handlers.
func RunMiddleware ¶
func RunMiddleware(t *testing.T, mw celeris.HandlerFunc, opts ...celeristest.Option) (*celeristest.ResponseRecorder, error)
RunMiddleware creates a test context with GET / and runs the middleware. c.Next() returns nil (no-op handler) for isolated middleware testing.
func RunMiddlewareWithMethod ¶
func RunMiddlewareWithMethod(t *testing.T, mw celeris.HandlerFunc, method, path string, opts ...celeristest.Option) (*celeristest.ResponseRecorder, error)
RunMiddlewareWithMethod creates a test context with the given method and path, then runs the middleware.
Types ¶
This section is empty.