testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 13 Imported by: 0

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

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

func AssertError(t *testing.T, err error, expectedMessage string)

AssertError is a test helper that fails the test if err is nil.

func AssertFalse

func AssertFalse(t *testing.T, condition bool, message string)

AssertFalse is a test helper for boolean assertions.

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError is a test helper that fails the test if err is not nil.

func AssertTrue

func AssertTrue(t *testing.T, condition bool, message string)

AssertTrue is a test helper for boolean assertions.

func SetupTestDB

func SetupTestDB(t *testing.T) *sql.DB

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

func NewTestApp(t *testing.T, options ...framework.AppOption) *TestApp

NewTestApp creates a test application with default configuration and automatic cleanup.

func (*TestApp) Start

func (ta *TestApp) Start(t *testing.T)

Start starts the test application with a timeout.

func (*TestApp) Stop

func (ta *TestApp) Stop(t *testing.T)

Stop stops the test application.

func (*TestApp) WaitForReady

func (ta *TestApp) WaitForReady(t *testing.T, timeout time.Duration)

WaitForReady waits for the application to be ready.

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.

func (*TestBundle) Name

func (b *TestBundle) Name() string

Name implements the Bundle interface.

func (*TestBundle) Stop

func (b *TestBundle) Stop(ctx context.Context) error

Stop 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.

func (*TestComponent) Start

func (c *TestComponent) Start(ctx context.Context) error

Start implements the Component interface.

func (*TestComponent) Stop

func (c *TestComponent) Stop(ctx context.Context) error

Stop implements the Component interface.

type TestHTTPClient

type TestHTTPClient struct {
	BaseURL string
	Client  *http.Client
}

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.

func (*TestHTTPClient) Get

func (c *TestHTTPClient) Get(t *testing.T, path string) *http.Response

Get performs a GET request for testing.

type TestServer

type TestServer struct {
	Server *httptest.Server
	URL    string
}

TestServer provides utilities for testing HTTP servers.

func NewTestServer

func NewTestServer(handler http.Handler) *TestServer

NewTestServer creates a test HTTP server for testing.

func (*TestServer) Close

func (ts *TestServer) Close()

Close closes the test server.

Jump to

Keyboard shortcuts

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