testkit

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package testkit is the generic test toolkit: infrastructure-free suites, HTTP mocks, assertion helpers and the integration-test gate. Event-bus helpers live in testkit/eventtest and container fixtures in testkit/containers; the platform-composite suites remain in shared/testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertDeepEqual

func AssertDeepEqual(t assert.TestingT, expected, actual any, msgAndArgs ...any) bool

BusinessLogicAssertions provides specialized assertions for business logic testing

func ConvertFromHTTPHeaders

func ConvertFromHTTPHeaders(headers http.Header) map[string]string

ConvertFromHTTPHeaders converts http.Header to simple string map (takes first value). Keys come back in canonical MIME form (e.g. "X-Request-Id"), as stored by http.Header.

func ConvertToHTTPHeaders

func ConvertToHTTPHeaders(headers map[string]string) http.Header

ConvertToHTTPHeaders converts simple string map to http.Header format

func RequireEventually

func RequireEventually(t require.TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...any)

RequireEventually is like testify's Eventually but with better error messages

func RunLiteTestSuite

func RunLiteTestSuite(t *testing.T, testSuite suite.TestingSuite)

RunLiteTestSuite runs a test suite with the lite framework

func RunTestSuite

func RunTestSuite(t *testing.T, testSuite suite.TestingSuite)

RunTestSuite runs a testify suite.

func ShouldRunIntegrationTests

func ShouldRunIntegrationTests() bool

ShouldRunIntegrationTests reports whether integration tests that require external infrastructure (Docker, Postgres, RabbitMQ) should run. Enable them with INTEGRATION_TESTS=true; they never run in -short mode.

Types

type ConcurrencyAssertions

type ConcurrencyAssertions struct {
	// contains filtered or unexported fields
}

ConcurrencyAssertions provides specialized assertions for concurrency testing

func NewConcurrencyAssertions

func NewConcurrencyAssertions(t assert.TestingT) *ConcurrencyAssertions

NewConcurrencyAssertions creates new concurrency assertion helper

func (*ConcurrencyAssertions) AssertGoroutineCleanup

func (a *ConcurrencyAssertions) AssertGoroutineCleanup(initialCount int, finalCount int, tolerance int, msgAndArgs ...any) bool

AssertGoroutineCleanup verifies goroutines were properly cleaned up

func (*ConcurrencyAssertions) AssertNoRaceConditions

func (a *ConcurrencyAssertions) AssertNoRaceConditions(expectedCount int, actualCount int, msgAndArgs ...any) bool

AssertNoRaceConditions verifies no race conditions occurred

type HTTPAssertions

type HTTPAssertions struct {
	// contains filtered or unexported fields
}

func NewHTTPAssertions

func NewHTTPAssertions(t assert.TestingT) *HTTPAssertions

NewHTTPAssertions creates new HTTP assertion helper

func (*HTTPAssertions) AssertContainsHeaders

func (a *HTTPAssertions) AssertContainsHeaders(headers map[string]string, expectedHeaders map[string]string, msgAndArgs ...any) bool

AssertContainsHeaders verifies response contains expected headers

func (*HTTPAssertions) AssertJSONResponse

func (a *HTTPAssertions) AssertJSONResponse(body []byte, expectedFields map[string]any, msgAndArgs ...any) bool

AssertJSONResponse verifies JSON response structure

func (*HTTPAssertions) AssertStatusCode

func (a *HTTPAssertions) AssertStatusCode(actual, expected int, msgAndArgs ...any) bool

AssertStatusCode verifies HTTP status code

type LiteTestSuite

type LiteTestSuite struct {
	suite.Suite
	HTTPClient   *httpclient.Client
	TestTimeout  time.Duration
	CleanupFuncs []func()
}

func (*LiteTestSuite) SetupSuite

func (s *LiteTestSuite) SetupSuite()

SetupSuite initializes lightweight test infrastructure

func (*LiteTestSuite) SetupTest

func (s *LiteTestSuite) SetupTest()

SetupTest runs before each test

func (*LiteTestSuite) TearDownSuite

func (s *LiteTestSuite) TearDownSuite()

TearDownSuite cleans up test infrastructure

func (*LiteTestSuite) TearDownTest

func (s *LiteTestSuite) TearDownTest()

TearDownTest runs after each test

func (*LiteTestSuite) WithTimeout

func (s *LiteTestSuite) WithTimeout(fn func())

WithTimeout runs a function with the test timeout

type MockHTTPClient

type MockHTTPClient struct {
	mock.Mock
	Responses map[string]MockHTTPResponse
	// contains filtered or unexported fields
}

func NewMockHTTPClient

func NewMockHTTPClient() *MockHTTPClient

NewMockHTTPClient creates a new mock HTTP client

func (*MockHTTPClient) ClearMockResponses

func (m *MockHTTPClient) ClearMockResponses()

ClearMockResponses clears all predefined responses

func (*MockHTTPClient) Delete

func (m *MockHTTPClient) Delete(ctx context.Context, path string, headers map[string]string) (*httpclient.Response, error)

Delete mocks HTTP DELETE requests

func (*MockHTTPClient) Get

func (m *MockHTTPClient) Get(ctx context.Context, path string, headers map[string]string) (*httpclient.Response, error)

Get mocks HTTP GET requests

func (*MockHTTPClient) Post

func (m *MockHTTPClient) Post(ctx context.Context, path string, body []byte, headers map[string]string) (*httpclient.Response, error)

Post mocks HTTP POST requests

func (*MockHTTPClient) Put

func (m *MockHTTPClient) Put(ctx context.Context, path string, body []byte, headers map[string]string) (*httpclient.Response, error)

Put mocks HTTP PUT requests

func (*MockHTTPClient) SetMockResponse

func (m *MockHTTPClient) SetMockResponse(path string, response MockHTTPResponse)

SetMockResponse sets a predefined response for a specific path

type MockHTTPResponse

type MockHTTPResponse struct {
	StatusCode int
	Body       []byte
	Headers    map[string]string
	Error      error
}

MockHTTPResponse represents a mock HTTP response

type MockTime

type MockTime struct {
	FrozenTime time.Time
}

TestEventHandler is a testing event handler that collects events

func NewMockTime

func NewMockTime() *MockTime

NewMockTime creates a new mock time instance

func (*MockTime) AddTime

func (m *MockTime) AddTime(d time.Duration)

AddTime adds duration to the frozen time

func (*MockTime) Now

func (m *MockTime) Now() time.Time

Now returns the frozen time

func (*MockTime) SetTime

func (m *MockTime) SetTime(t time.Time)

SetTime sets the frozen time

type PerformanceAssertions

type PerformanceAssertions struct {
	// contains filtered or unexported fields
}

DatabaseAssertions provides specialized assertions for database testing

func NewPerformanceAssertions

func NewPerformanceAssertions(t assert.TestingT) *PerformanceAssertions

NewPerformanceAssertions creates new performance assertion helper

func (*PerformanceAssertions) AssertExecutionTime

func (a *PerformanceAssertions) AssertExecutionTime(duration time.Duration, maxDuration time.Duration, msgAndArgs ...any) bool

AssertExecutionTime verifies execution time is within bounds

func (*PerformanceAssertions) AssertMinimumThroughput

func (a *PerformanceAssertions) AssertMinimumThroughput(operations int, duration time.Duration, minimumOpsPerSecond float64, msgAndArgs ...any) bool

AssertMinimumThroughput verifies minimum operations per second

type PerformanceTestHelper

type PerformanceTestHelper struct {
	StartTime time.Time
	Metrics   map[string]time.Duration
}

SecurityTestHelper provides utilities for testing cryptographic security

func NewPerformanceTestHelper

func NewPerformanceTestHelper() *PerformanceTestHelper

NewPerformanceTestHelper creates performance testing utilities

func (*PerformanceTestHelper) AssertPerformance

func (h *PerformanceTestHelper) AssertPerformance(metricName string, maxDuration time.Duration) bool

AssertPerformance asserts that a metric is within expected bounds

func (*PerformanceTestHelper) GetMetric

func (h *PerformanceTestHelper) GetMetric(metricName string) time.Duration

GetMetric returns a recorded metric

func (*PerformanceTestHelper) StartTimer

func (h *PerformanceTestHelper) StartTimer()

StartTimer starts a performance timer

func (*PerformanceTestHelper) StopTimer

func (h *PerformanceTestHelper) StopTimer(metricName string) time.Duration

StopTimer stops the timer and records the metric

type TestDatabase

type TestDatabase struct {
	ConnectionString string
	CleanupQueries   []string
}

TestDatabase provides utilities for database testing

func NewTestDatabase

func NewTestDatabase(connString string) *TestDatabase

NewTestDatabase creates a new test database instance

func (*TestDatabase) AddCleanupQuery

func (db *TestDatabase) AddCleanupQuery(query string)

AddCleanupQuery adds a query to run during cleanup

Directories

Path Synopsis
Package containers starts real PostgreSQL, Redis and RabbitMQ instances in Docker for the integration tier, using testcontainers-go.
Package containers starts real PostgreSQL, Redis and RabbitMQ instances in Docker for the integration tier, using testcontainers-go.
Package eventtest provides event-bus test doubles and assertions for the generic eventbus package: mock publisher/subscriber, a collecting event handler, signing helpers and event/security assertions.
Package eventtest provides event-bus test doubles and assertions for the generic eventbus package: mock publisher/subscriber, a collecting event handler, signing helpers and event/security assertions.

Jump to

Keyboard shortcuts

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