Documentation
¶
Overview ¶
Package testutil provides testing utilities for the Forge framework.
This package contains common testing patterns, mock implementations, and utility functions to make testing Forge applications easier and more reliable.
Index ¶
- func AssertEqual[T comparable](t *testing.T, expected, actual T)
- func AssertError(t *testing.T, err error, expectedMessage string)
- func AssertFalse(t *testing.T, condition bool, message string)
- func AssertNoError(t *testing.T, err error)
- func AssertTrue(t *testing.T, condition bool, message string)
- func SetupTestDB(t *testing.T) *sql.DB
- func SetupTestRedis(t *testing.T) redis.UniversalClient
- type TestApp
- type TestBundle
- type TestComponent
- type TestHTTPClient
- type TestServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEqual ¶
func AssertEqual[T comparable](t *testing.T, expected, actual T)
AssertEqual is a test helper for equality assertions.
func AssertError ¶
AssertError is a test helper that fails the test if err is nil.
func AssertFalse ¶
AssertFalse is a test helper for boolean assertions.
func AssertNoError ¶
AssertNoError is a test helper that fails the test if err is not nil.
func AssertTrue ¶
AssertTrue is a test helper for boolean assertions.
func SetupTestDB ¶
SetupTestDB creates a test database connection for integration testing. Requires PostgreSQL to be running.
func SetupTestRedis ¶
func SetupTestRedis(t *testing.T) redis.UniversalClient
SetupTestRedis creates a test Redis client for integration testing. Requires Redis to be running.
Types ¶
type TestApp ¶
type TestApp struct {
App *framework.App
Config *config.BaseConfig
// contains filtered or unexported fields
}
TestApp wraps a Forge application for testing with automatic cleanup.
func NewTestApp ¶
NewTestApp creates a test application with default configuration and automatic cleanup.
type TestBundle ¶
type TestBundle struct {
BundleName string
InitCalled bool
InitError error
StopCalled bool
StopError error
}
TestBundle provides a mock Bundle implementation for testing.
func NewTestBundle ¶
func NewTestBundle(name string) *TestBundle
NewTestBundle creates a new test bundle.
func (*TestBundle) Initialize ¶
func (b *TestBundle) Initialize(app *framework.App) error
Initialize implements the Bundle interface.
type TestComponent ¶
type TestComponent struct {
Name string
StartCalled bool
StopCalled bool
StartError error
StopError error
// contains filtered or unexported fields
}
TestComponent provides a mock Component implementation for testing.
func NewTestComponent ¶
func NewTestComponent(name string) *TestComponent
NewTestComponent creates a new test component.
func (*TestComponent) HealthChecks ¶
func (c *TestComponent) HealthChecks() []forgeHealth.Check
HealthChecks implements the HealthContributor interface.
type TestHTTPClient ¶
TestHTTPClient provides HTTP client utilities for testing.
func NewTestHTTPClient ¶
func NewTestHTTPClient(baseURL string) *TestHTTPClient
NewTestHTTPClient creates an HTTP client for testing Forge HTTP endpoints.
func (*TestHTTPClient) CheckHealth ¶
func (c *TestHTTPClient) CheckHealth(t *testing.T)
CheckHealth performs a health check and validates the response.
type TestServer ¶
TestServer provides utilities for testing HTTP servers.
func NewTestServer ¶
func NewTestServer(handler http.Handler) *TestServer
NewTestServer creates a test HTTP server for testing.