Documentation
¶
Overview ¶
Package helpers provides common test utilities for integration and unit tests. Following Go 2025 best practices, all helper functions use t.Helper() to ensure proper error reporting in test output.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoRequest ¶
DoRequest creates and executes an HTTP request with common test settings. It automatically handles CSRF protection by setting the Origin header for state-changing requests (POST, PUT, DELETE, PATCH).
Usage:
resp := helpers.DoRequest(t, ts.Server.URL, helpers.RequestOptions{
Method: http.MethodPost,
Path: "/api/v1/refresh",
Token: "test-token",
})
defer resp.Body.Close()
Types ¶
type RequestOptions ¶
type RequestOptions struct {
Method string
Path string
Body io.Reader
Token string
SetOrigin bool // Automatically set Origin header for CSRF protection
ExtraHeader map[string]string
}
RequestOptions configures HTTP request creation
type TestServer ¶
TestServer wraps a test HTTP server with its configuration
func NewTestServer ¶
func NewTestServer(t *testing.T, opts TestServerOptions) *TestServer
NewTestServer creates a new test HTTP server with the given configuration. It automatically marks the calling function as a test helper.
Usage:
ts := helpers.NewTestServer(t, helpers.TestServerOptions{
DataDir: t.TempDir(),
APIToken: "test-token",
})
defer ts.Close()
func NewTestServerWithConfig ¶
func NewTestServerWithConfig(t *testing.T, cfg jobs.Config) *TestServer
NewTestServerWithConfig creates a test server from an existing config. Use this when you need full control over the config structure.
func (*TestServer) Close ¶
func (ts *TestServer) Close()
Close closes the test server and cleans up resources