testutil

package
v0.0.0-...-6a3e998 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package testutil provides common test utilities and helpers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertJSONResponse

func AssertJSONResponse(t *testing.T, w *httptest.ResponseRecorder, expected any)

AssertJSONResponse asserts JSON response matches expected structure

func ContextWithTimeout

func ContextWithTimeout(t *testing.T, timeout time.Duration) (context.Context, context.CancelFunc)

ContextWithTimeout creates a context with timeout and cleanup

func GenerateLargePayload

func GenerateLargePayload(sizeBytes int) []byte

GenerateLargePayload generates a large payload for testing

func RandomString

func RandomString(length int) string

RandomString generates a random string of given length

func WaitForCondition

func WaitForCondition(t *testing.T, timeout time.Duration, check func() bool, message string)

WaitForCondition waits for a condition to be true

Types

type Agent

type Agent struct {
	ID          string         `json:"id"`
	TenantID    string         `json:"tenant_id"`
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Config      map[string]any `json:"config"`
}

Agent represents a test agent

type Context

type Context struct {
	ID        string         `json:"id"`
	AgentID   string         `json:"agent_id"`
	ModelID   string         `json:"model_id"`
	MaxTokens int            `json:"max_tokens"`
	Metadata  map[string]any `json:"metadata"`
	CreatedAt time.Time      `json:"created_at"`
}

Context represents a test context

type HTTPClient

type HTTPClient struct {
	BaseURL   string
	AuthToken string
	TenantID  string
	Client    *http.Client
}

HTTPClient provides a test HTTP client

func NewHTTPClient

func NewHTTPClient(config *TestConfig) *HTTPClient

NewHTTPClient creates a new test HTTP client

func (*HTTPClient) Request

func (c *HTTPClient) Request(method, path string, body any) (*http.Response, error)

Request makes an HTTP request with standard headers

type MockClock

type MockClock struct {
	CurrentTime time.Time
}

MockClock provides a mock clock for testing

func (*MockClock) Advance

func (mc *MockClock) Advance(d time.Duration)

Advance advances the mock clock

func (*MockClock) Now

func (mc *MockClock) Now() time.Time

Now returns the mock current time

type Model

type Model struct {
	ID        string `json:"id"`
	TenantID  string `json:"tenant_id"`
	Name      string `json:"name"`
	Provider  string `json:"provider"`
	ModelType string `json:"model_type"`
}

Model represents a test model

type TestConfig

type TestConfig struct {
	DatabaseDSN   string
	RedisAddr     string
	APIBaseURL    string
	TestTenantID  string
	TestAuthToken string
}

TestConfig holds test configuration

func LoadTestConfig

func LoadTestConfig() *TestConfig

LoadTestConfig loads test configuration from environment

type TestDatabase

type TestDatabase struct {
	DB *sql.DB
}

TestDatabase provides test database utilities

func NewTestDatabase

func NewTestDatabase(t *testing.T, dsn string) *TestDatabase

NewTestDatabase creates a new test database connection

func (*TestDatabase) Cleanup

func (tdb *TestDatabase) Cleanup(t *testing.T, tenantID string)

Cleanup cleans up test data

func (*TestDatabase) Close

func (tdb *TestDatabase) Close()

Close closes the database connection

type TestFixtures

type TestFixtures struct {
	Contexts []Context
	Agents   []Agent
	Models   []Model
}

TestFixtures provides test data fixtures

func LoadFixtures

func LoadFixtures(tenantID string) *TestFixtures

LoadFixtures loads test fixtures

type TestMetrics

type TestMetrics struct {
	Counters map[string]int64
	Gauges   map[string]float64
	// contains filtered or unexported fields
}

TestMetrics provides test metrics collection

func NewTestMetrics

func NewTestMetrics() *TestMetrics

NewTestMetrics creates a new test metrics collector

func (*TestMetrics) GetCounter

func (tm *TestMetrics) GetCounter(name string) int64

GetCounter gets a counter value

func (*TestMetrics) GetGauge

func (tm *TestMetrics) GetGauge(name string) float64

GetGauge gets a gauge value

func (*TestMetrics) IncrCounter

func (tm *TestMetrics) IncrCounter(name string, value int64)

IncrCounter increments a counter

func (*TestMetrics) SetGauge

func (tm *TestMetrics) SetGauge(name string, value float64)

SetGauge sets a gauge value

type TestServer

type TestServer struct {
	Router *gin.Engine
}

TestServer provides a test Gin server

func NewTestServer

func NewTestServer() *TestServer

NewTestServer creates a new test server

func (*TestServer) AddAuthMiddleware

func (ts *TestServer) AddAuthMiddleware()

AddAuthMiddleware adds test authentication middleware

func (*TestServer) ServeHTTP

func (ts *TestServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

Jump to

Keyboard shortcuts

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