Documentation
¶
Overview ¶
Package testingtools provides test utilities for v2 handler and middleware testing, including a test parser, test router, and initialization helpers.
Index ¶
- func AssertResponse(parser *v2wf.FakeParserV2, expectedStatus int, expectedContentType string) bool
- func GetSetCookies(ctx *v2wf.RequestContext) []*http.Cookie
- func InitTestingV2() (*v2response.Handler, v2response.Registry, renderers.Renderer)
- func InitTestingV2WithWorker() (*v2response.Handler, v2response.Registry, renderers.Renderer, workers.Worker)
- func SetRequestCookie(ctx *v2wf.RequestContext, name, value string)
- func TestRequestContext() *v2wf.RequestContext
- func TestRequestContextWithSession() *v2wf.RequestContext
- type TestParserV2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertResponse ¶
func AssertResponse(parser *v2wf.FakeParserV2, expectedStatus int, expectedContentType string) bool
AssertResponse checks that the parser captured the expected response.
func GetSetCookies ¶
func GetSetCookies(ctx *v2wf.RequestContext) []*http.Cookie
GetSetCookies returns the cookies that were set on the response during handler execution.
func InitTestingV2 ¶
func InitTestingV2() (*v2response.Handler, v2response.Registry, renderers.Renderer)
InitTestingV2 creates a minimal v2 testing setup with a TestParserV2, a response handler with a registry, and default renderers. It does not require a real database or framework.
func InitTestingV2WithWorker ¶
func InitTestingV2WithWorker() (*v2response.Handler, v2response.Registry, renderers.Renderer, workers.Worker)
InitTestingV2WithWorker creates a testing setup that includes an in-process worker pool for testing async job behavior.
func SetRequestCookie ¶
func SetRequestCookie(ctx *v2wf.RequestContext, name, value string)
SetRequestCookie sets a cookie on the test parser for testing session middleware.
func TestRequestContext ¶
func TestRequestContext() *v2wf.RequestContext
TestRequestContext creates a RequestContext suitable for testing handlers and middleware without a real HTTP framework.
func TestRequestContextWithSession ¶
func TestRequestContextWithSession() *v2wf.RequestContext
TestRequestContextWithSession creates a RequestContext with session and flash objects for testing session-aware handlers.
Types ¶
type TestParserV2 ¶
type TestParserV2 struct {
*v2wf.FakeParserV2
// SendResponseError, when non-nil, is returned by SendResponse
// instead of capturing the response. Useful for testing error paths.
SendResponseError error
}
TestParserV2 is an enhanced FakeParserV2 for handler testing. It provides additional fields for asserting response state and controlling parser behavior during tests.
func NewTestParserV2 ¶
func NewTestParserV2() *TestParserV2
NewTestParserV2 creates a TestParserV2 with initialized maps.
func (*TestParserV2) SendResponse ¶
func (p *TestParserV2) SendResponse(status int, contentType string, body []byte) error
SendResponse captures the response or returns the configured error. Before writing (or returning the configured error), the before-commit hook runner is invoked so that session cookies and other pre-write side effects are persisted.
func (*TestParserV2) SetBeforeCommitHookRunner ¶
func (p *TestParserV2) SetBeforeCommitHookRunner(fn func() error)
SetBeforeCommitHookRunner delegates to the embedded FakeParserV2.
func (*TestParserV2) SetCommitState ¶
func (p *TestParserV2) SetCommitState(cs *v2wf.CommitState)
SetCommitState delegates to the embedded FakeParserV2.