testing

package
v1.0.83 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupTestData

func CleanupTestData(app *TestApp, endpoint, id string) error

CleanupTestData removes test data

func CreateTestData

func CreateTestData(app *TestApp, endpoint string, data map[string]any) (string, error)

CreateTestData creates test data for scenarios

func NewMockDatapoint

func NewMockDatapoint(value float64, unit types.StandardUnit) types.Datapoint

NewMockDatapoint creates a mock Datapoint for testing

func NewMockDeleteAlarmsOutput

func NewMockDeleteAlarmsOutput() *cloudwatch.DeleteAlarmsOutput

NewMockDeleteAlarmsOutput creates a mock DeleteAlarmsOutput

func NewMockDeleteAnomalyDetectorOutput

func NewMockDeleteAnomalyDetectorOutput() *cloudwatch.DeleteAnomalyDetectorOutput

NewMockDeleteAnomalyDetectorOutput creates a mock DeleteAnomalyDetectorOutput

func NewMockDescribeAlarmsOutput

func NewMockDescribeAlarmsOutput(alarms []types.MetricAlarm) *cloudwatch.DescribeAlarmsOutput

NewMockDescribeAlarmsOutput creates a mock DescribeAlarmsOutput with alarms

func NewMockDescribeAnomalyDetectorsOutput

func NewMockDescribeAnomalyDetectorsOutput(detectors []types.AnomalyDetector) *cloudwatch.DescribeAnomalyDetectorsOutput

NewMockDescribeAnomalyDetectorsOutput creates a mock DescribeAnomalyDetectorsOutput

func NewMockDimension

func NewMockDimension(name, value string) types.Dimension

NewMockDimension creates a mock Dimension for testing

func NewMockGetMetricDataOutput

func NewMockGetMetricDataOutput(results []types.MetricDataResult) *cloudwatch.GetMetricDataOutput

NewMockGetMetricDataOutput creates a mock GetMetricDataOutput with results

func NewMockGetMetricStatisticsOutput

func NewMockGetMetricStatisticsOutput(datapoints []types.Datapoint) *cloudwatch.GetMetricStatisticsOutput

NewMockGetMetricStatisticsOutput creates a mock GetMetricStatisticsOutput with datapoints

func NewMockListMetricsOutput

func NewMockListMetricsOutput(metrics []types.Metric) *cloudwatch.ListMetricsOutput

NewMockListMetricsOutput creates a mock ListMetricsOutput with metrics

func NewMockListTagsForResourceOutput

func NewMockListTagsForResourceOutput(tags []types.Tag) *cloudwatch.ListTagsForResourceOutput

NewMockListTagsForResourceOutput creates a mock ListTagsForResourceOutput

func NewMockMetric

func NewMockMetric(name, namespace string) types.Metric

NewMockMetric creates a mock Metric for testing

func NewMockMetricAlarm

func NewMockMetricAlarm(name, metricName string, threshold float64) types.MetricAlarm

NewMockMetricAlarm creates a mock MetricAlarm for testing

func NewMockMetricDatum

func NewMockMetricDatum(name string, value float64, unit types.StandardUnit) types.MetricDatum

NewMockMetricDatum creates a mock MetricDatum for testing

func NewMockPutAnomalyDetectorOutput

func NewMockPutAnomalyDetectorOutput() *cloudwatch.PutAnomalyDetectorOutput

NewMockPutAnomalyDetectorOutput creates a mock PutAnomalyDetectorOutput

func NewMockPutMetricAlarmOutput

func NewMockPutMetricAlarmOutput() *cloudwatch.PutMetricAlarmOutput

NewMockPutMetricAlarmOutput creates a mock PutMetricAlarmOutput

func NewMockPutMetricDataOutput

func NewMockPutMetricDataOutput() *cloudwatch.PutMetricDataOutput

NewMockPutMetricDataOutput creates a mock PutMetricDataOutput

func NewMockTag

func NewMockTag(key, value string) types.Tag

NewMockTag creates a mock Tag for testing

func NewMockTagResourceOutput

func NewMockTagResourceOutput() *cloudwatch.TagResourceOutput

NewMockTagResourceOutput creates a mock TagResourceOutput

func NewMockUntagResourceOutput

func NewMockUntagResourceOutput() *cloudwatch.UntagResourceOutput

NewMockUntagResourceOutput creates a mock UntagResourceOutput

func RunScenarios

func RunScenarios(t *testing.T, app *TestApp, scenarios []TestScenario)

RunScenarios executes a collection of test scenarios

func TestRateLimiting

func TestRateLimiting(t *testing.T, app *TestApp, endpoint string, limit int)

TestRateLimiting is a helper function for testing rate limiting

Types

type AlarmState

type AlarmState string

AlarmState represents the state of a CloudWatch alarm

const (
	AlarmStateOK               AlarmState = "OK"
	AlarmStateAlarm            AlarmState = "ALARM"
	AlarmStateInsufficientData AlarmState = "INSUFFICIENT_DATA"
)

type AuthConfig

type AuthConfig struct {
	Token    string
	TenantID string
	UserID   string
	Scopes   []string
}

AuthConfig holds authentication configuration for tests

type ComparisonOperator

type ComparisonOperator string

ComparisonOperator represents alarm comparison operators

const (
	ComparisonGreaterThanThreshold                     ComparisonOperator = "GreaterThanThreshold"
	ComparisonGreaterThanOrEqualToThreshold            ComparisonOperator = "GreaterThanOrEqualToThreshold"
	ComparisonLessThanThreshold                        ComparisonOperator = "LessThanThreshold"
	ComparisonLessThanOrEqualToThreshold               ComparisonOperator = "LessThanOrEqualToThreshold"
	ComparisonLessThanLowerOrGreaterThanUpperThreshold ComparisonOperator = "LessThanLowerOrGreaterThanUpperThreshold"
	ComparisonLessThanLowerThreshold                   ComparisonOperator = "LessThanLowerThreshold"
	ComparisonGreaterThanUpperThreshold                ComparisonOperator = "GreaterThanUpperThreshold"
)

type ConnectionState

type ConnectionState string

ConnectionState represents the state of a WebSocket connection

const (
	ConnectionStateActive       ConnectionState = "ACTIVE"
	ConnectionStateDisconnected ConnectionState = "DISCONNECTED"
	ConnectionStateStale        ConnectionState = "STALE"
)

type LoadTestConfig

type LoadTestConfig struct {
	ConcurrentUsers   int           `json:"concurrent_users"`
	TotalRequests     int           `json:"total_requests"`
	Duration          time.Duration `json:"duration"`
	RampUpDuration    time.Duration `json:"ramp_up_duration"`
	MaxLatency        time.Duration `json:"max_latency"`
	ErrorThreshold    float64       `json:"error_threshold"`
	RequestsPerSecond int           `json:"requests_per_second"`
}

LoadTestConfig configures load testing parameters

type LoadTestResult

type LoadTestResult struct {
	StartTime          time.Time     `json:"start_time"`
	EndTime            time.Time     `json:"end_time"`
	Errors             []string      `json:"errors"`
	MaxLatency         time.Duration `json:"max_latency"`
	P95Latency         time.Duration `json:"p95_latency"`
	P99Latency         time.Duration `json:"p99_latency"`
	AverageLatency     time.Duration `json:"average_latency"`
	MinLatency         time.Duration `json:"min_latency"`
	RequestsPerSecond  float64       `json:"requests_per_second"`
	ErrorRate          float64       `json:"error_rate"`
	Duration           time.Duration `json:"duration"`
	TotalRequests      int           `json:"total_requests"`
	SuccessfulRequests int           `json:"successful_requests"`
	FailedRequests     int           `json:"failed_requests"`
}

LoadTestResult represents the result of a load test

type LoadTester

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

LoadTester provides load testing capabilities

func NewLoadTester

func NewLoadTester(app *TestApp, config *LoadTestConfig) *LoadTester

NewLoadTester creates a new load tester

func (*LoadTester) RunLoadTest

func (lt *LoadTester) RunLoadTest(ctx context.Context, request func(*TestApp) *TestResponse) (*LoadTestResult, error)

RunLoadTest executes a load test scenario

type MetricUnit

type MetricUnit string

MetricUnit represents CloudWatch metric units

const (
	MetricUnitNone           MetricUnit = "None"
	MetricUnitSeconds        MetricUnit = "Seconds"
	MetricUnitMicroseconds   MetricUnit = "Microseconds"
	MetricUnitMilliseconds   MetricUnit = "Milliseconds"
	MetricUnitBytes          MetricUnit = "Bytes"
	MetricUnitKilobytes      MetricUnit = "Kilobytes"
	MetricUnitMegabytes      MetricUnit = "Megabytes"
	MetricUnitGigabytes      MetricUnit = "Gigabytes"
	MetricUnitTerabytes      MetricUnit = "Terabytes"
	MetricUnitBits           MetricUnit = "Bits"
	MetricUnitKilobits       MetricUnit = "Kilobits"
	MetricUnitMegabits       MetricUnit = "Megabits"
	MetricUnitGigabits       MetricUnit = "Gigabits"
	MetricUnitTerabits       MetricUnit = "Terabits"
	MetricUnitPercent        MetricUnit = "Percent"
	MetricUnitCount          MetricUnit = "Count"
	MetricUnitCountPerSecond MetricUnit = "Count/Second"
)

type MockAPIGatewayConfig

type MockAPIGatewayConfig struct {
	ErrorRates     map[string]float64
	ConnectionTTL  int64
	MaxMessageSize int64
	NetworkDelay   time.Duration
}

MockAPIGatewayConfig configures the behavior of the API Gateway mock

func DefaultMockAPIGatewayConfig

func DefaultMockAPIGatewayConfig() *MockAPIGatewayConfig

DefaultMockAPIGatewayConfig returns default configuration

type MockAPIGatewayError

type MockAPIGatewayError struct {
	Code       string
	Message    string
	StatusCode int
	Retryable  bool
}

MockAPIGatewayError implements the APIError interface for testing

func (*MockAPIGatewayError) Error

func (e *MockAPIGatewayError) Error() string

func (*MockAPIGatewayError) ErrorCode

func (e *MockAPIGatewayError) ErrorCode() string

func (*MockAPIGatewayError) HTTPStatusCode

func (e *MockAPIGatewayError) HTTPStatusCode() int

func (*MockAPIGatewayError) IsRetryable

func (e *MockAPIGatewayError) IsRetryable() bool

type MockAPIGatewayManagementClient

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

MockAPIGatewayManagementClient provides a mock implementation of API Gateway Management API

func NewMockAPIGatewayManagementClient

func NewMockAPIGatewayManagementClient() *MockAPIGatewayManagementClient

NewMockAPIGatewayManagementClient creates a new mock API Gateway Management client

func (*MockAPIGatewayManagementClient) DeleteConnection

func (m *MockAPIGatewayManagementClient) DeleteConnection(_ context.Context, connectionID string) error

DeleteConnection terminates a WebSocket connection

func (*MockAPIGatewayManagementClient) GetActiveConnections

func (m *MockAPIGatewayManagementClient) GetActiveConnections() map[string]*MockConnection

GetActiveConnections returns all active connections

func (*MockAPIGatewayManagementClient) GetCallCount

func (m *MockAPIGatewayManagementClient) GetCallCount(operation string) int

GetCallCount returns the number of times an operation was called

func (*MockAPIGatewayManagementClient) GetConnection

func (m *MockAPIGatewayManagementClient) GetConnection(_ context.Context, connectionID string) (*MockConnectionInfo, error)

GetConnection retrieves connection information

func (*MockAPIGatewayManagementClient) GetConnectionState

func (m *MockAPIGatewayManagementClient) GetConnectionState(connectionID string) *MockConnection

GetConnectionState returns a copy of the connection state

func (*MockAPIGatewayManagementClient) GetMessageCount

func (m *MockAPIGatewayManagementClient) GetMessageCount(connectionID string) int

GetMessageCount returns the number of messages sent to a connection

func (*MockAPIGatewayManagementClient) GetMessages

func (m *MockAPIGatewayManagementClient) GetMessages(connectionID string) [][]byte

GetMessages returns all messages sent to a connection

func (*MockAPIGatewayManagementClient) PostToConnection

func (m *MockAPIGatewayManagementClient) PostToConnection(_ context.Context, connectionID string, data []byte) error

PostToConnection sends data to a WebSocket connection

func (*MockAPIGatewayManagementClient) Reset

func (m *MockAPIGatewayManagementClient) Reset()

Reset clears all mock state

func (*MockAPIGatewayManagementClient) SimulateConnectionExpiry

func (m *MockAPIGatewayManagementClient) SimulateConnectionExpiry()

SimulateConnectionExpiry marks connections as stale based on TTL

func (*MockAPIGatewayManagementClient) WithConfig

WithConfig sets the mock configuration

func (*MockAPIGatewayManagementClient) WithConnection

WithConnection adds a connection to the mock

func (*MockAPIGatewayManagementClient) WithError

WithError configures an error for a specific connection

type MockAWSService

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

MockAWSService provides a generic mock for AWS services Memory optimized for better alignment

func NewMockAWSService

func NewMockAWSService() *MockAWSService

NewMockAWSService creates a new mock AWS service

func (*MockAWSService) Call

func (m *MockAWSService) Call(operation string, _ any) (any, error)

Call simulates calling an AWS service operation

func (*MockAWSService) GetCallCount

func (m *MockAWSService) GetCallCount(operation string) int

GetCallCount returns the number of times an operation was called

func (*MockAWSService) Reset

func (m *MockAWSService) Reset()

Reset clears all mock state

func (*MockAWSService) WithError

func (m *MockAWSService) WithError(operation string, err error) *MockAWSService

WithError configures an error for an operation

func (*MockAWSService) WithResponse

func (m *MockAWSService) WithResponse(operation string, response any) *MockAWSService

WithResponse configures a response for an operation

type MockAlarmDefinition

type MockAlarmDefinition struct {
	UpdatedAt          time.Time          `json:"updated_at"`
	CreatedAt          time.Time          `json:"created_at"`
	StateUpdatedAt     time.Time          `json:"state_updated_at"`
	Dimensions         map[string]string  `json:"dimensions,omitempty"`
	StateReason        string             `json:"state_reason"`
	Statistic          Statistic          `json:"statistic"`
	ComparisonOperator ComparisonOperator `json:"comparison_operator"`
	TreatMissingData   string             `json:"treat_missing_data"`
	State              AlarmState         `json:"state"`
	AlarmName          string             `json:"alarm_name"`
	Namespace          string             `json:"namespace"`
	MetricName         string             `json:"metric_name"`
	AlarmDescription   string             `json:"alarm_description"`
	Threshold          float64            `json:"threshold"`
	Period             int32              `json:"period"`
	EvaluationPeriods  int32              `json:"evaluation_periods"`
}

MockAlarmDefinition represents a CloudWatch alarm

type MockCloudWatchAlarmsClient

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

MockCloudWatchAlarmsClient provides a mock implementation of CloudWatch Alarms

func NewMockCloudWatchAlarmsClient

func NewMockCloudWatchAlarmsClient() *MockCloudWatchAlarmsClient

NewMockCloudWatchAlarmsClient creates a new mock CloudWatch Alarms client

func (*MockCloudWatchAlarmsClient) DeleteAlarms

func (m *MockCloudWatchAlarmsClient) DeleteAlarms(_ context.Context, alarmNames []string) error

DeleteAlarms deletes one or more alarms

func (*MockCloudWatchAlarmsClient) DescribeAlarms

func (m *MockCloudWatchAlarmsClient) DescribeAlarms(_ context.Context, alarmNames []string) ([]*MockAlarmDefinition, error)

DescribeAlarms retrieves alarm information

func (*MockCloudWatchAlarmsClient) EvaluateAlarms

func (m *MockCloudWatchAlarmsClient) EvaluateAlarms(ctx context.Context) error

EvaluateAlarms evaluates all alarms against current metrics

func (*MockCloudWatchAlarmsClient) GetAlarm

func (m *MockCloudWatchAlarmsClient) GetAlarm(alarmName string) *MockAlarmDefinition

GetAlarm returns a copy of an alarm definition

func (*MockCloudWatchAlarmsClient) GetAllAlarms

func (m *MockCloudWatchAlarmsClient) GetAllAlarms() map[string]*MockAlarmDefinition

GetAllAlarms returns all alarm definitions

func (*MockCloudWatchAlarmsClient) GetCallCount

func (m *MockCloudWatchAlarmsClient) GetCallCount(operation string) int

GetCallCount returns the number of times an operation was called

func (*MockCloudWatchAlarmsClient) PutMetricAlarm

PutMetricAlarm creates or updates an alarm

func (*MockCloudWatchAlarmsClient) Reset

func (m *MockCloudWatchAlarmsClient) Reset()

Reset clears all mock state

func (*MockCloudWatchAlarmsClient) WithConfig

WithConfig sets the mock configuration

func (*MockCloudWatchAlarmsClient) WithError

func (m *MockCloudWatchAlarmsClient) WithError(operation string, err error) *MockCloudWatchAlarmsClient

WithError configures an error for a specific operation

func (*MockCloudWatchAlarmsClient) WithMetricsClient

WithMetricsClient sets the metrics client for alarm evaluation

type MockCloudWatchClient

type MockCloudWatchClient struct {
	mock.Mock
}

MockCloudWatchClient provides a testify-based mock of the AWS CloudWatch client that implements the exact AWS SDK interface, following the DynamORM pattern.

func NewMockCloudWatchClient

func NewMockCloudWatchClient() *MockCloudWatchClient

NewMockCloudWatchClient creates a new mock CloudWatch client

func (*MockCloudWatchClient) DeleteAlarms

DeleteAlarms deletes one or more alarms

func (*MockCloudWatchClient) DeleteAnomalyDetector

DeleteAnomalyDetector deletes an anomaly detector

func (*MockCloudWatchClient) DescribeAlarms

DescribeAlarms retrieves alarm information

func (*MockCloudWatchClient) DescribeAnomalyDetectors

DescribeAnomalyDetectors retrieves anomaly detector information

func (*MockCloudWatchClient) GetMetricData

GetMetricData retrieves metric data using metric queries

func (*MockCloudWatchClient) GetMetricStatistics

GetMetricStatistics retrieves statistics for a metric

func (*MockCloudWatchClient) ListMetrics

ListMetrics lists available metrics

func (*MockCloudWatchClient) ListTagsForResource

ListTagsForResource lists tags for a CloudWatch resource

func (*MockCloudWatchClient) PutAnomalyDetector

PutAnomalyDetector creates or updates an anomaly detector

func (*MockCloudWatchClient) PutMetricAlarm

PutMetricAlarm creates or updates an alarm

func (*MockCloudWatchClient) PutMetricData

PutMetricData publishes metric data to CloudWatch

func (*MockCloudWatchClient) TagResource

TagResource adds tags to a CloudWatch resource

func (*MockCloudWatchClient) UntagResource

UntagResource removes tags from a CloudWatch resource

type MockCloudWatchConfig

type MockCloudWatchConfig struct {
	// Maximum number of metrics per PutMetricData call
	MaxMetricsPerCall int
	// Simulate network delays
	NetworkDelay time.Duration
	// Auto-evaluate alarms when metrics are published
	AutoEvaluateAlarms bool
	// Metric retention period in hours
	MetricRetentionHours int
}

MockCloudWatchConfig configures the behavior of CloudWatch mocks

func DefaultMockCloudWatchConfig

func DefaultMockCloudWatchConfig() *MockCloudWatchConfig

DefaultMockCloudWatchConfig returns default configuration

type MockCloudWatchMetricsClient

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

MockCloudWatchMetricsClient provides a mock implementation of CloudWatch Metrics

func NewMockCloudWatchMetricsClient

func NewMockCloudWatchMetricsClient() *MockCloudWatchMetricsClient

NewMockCloudWatchMetricsClient creates a new mock CloudWatch Metrics client

func (*MockCloudWatchMetricsClient) GetAllMetrics

func (m *MockCloudWatchMetricsClient) GetAllMetrics() map[string][]*MockMetricDatum

GetAllMetrics returns all metrics across all namespaces

func (*MockCloudWatchMetricsClient) GetCallCount

func (m *MockCloudWatchMetricsClient) GetCallCount(operation string) int

GetCallCount returns the number of times an operation was called

func (*MockCloudWatchMetricsClient) GetMetricStatistics

func (m *MockCloudWatchMetricsClient) GetMetricStatistics(_ context.Context, namespace, metricName string, dimensions map[string]string, startTime, endTime time.Time, _ int32, statistics []Statistic) (map[Statistic]float64, error)

GetMetricStatistics retrieves statistics for a metric

func (*MockCloudWatchMetricsClient) GetMetrics

func (m *MockCloudWatchMetricsClient) GetMetrics(namespace string) []*MockMetricDatum

GetMetrics returns all metrics for a namespace

func (*MockCloudWatchMetricsClient) PutMetricData

func (m *MockCloudWatchMetricsClient) PutMetricData(_ context.Context, namespace string, metricData []*MockMetricDatum) error

PutMetricData publishes metric data to CloudWatch

func (*MockCloudWatchMetricsClient) Reset

func (m *MockCloudWatchMetricsClient) Reset()

Reset clears all mock state

func (*MockCloudWatchMetricsClient) WithConfig

WithConfig sets the mock configuration

func (*MockCloudWatchMetricsClient) WithError

WithError configures an error for a specific operation

type MockConnection

type MockConnection struct {
	CreatedAt    time.Time       `json:"created_at"`
	LastActiveAt time.Time       `json:"last_active_at"`
	Metadata     map[string]any  `json:"metadata,omitempty"`
	ID           string          `json:"id"`
	State        ConnectionState `json:"state"`
	SourceIP     string          `json:"source_ip"`
	UserAgent    string          `json:"user_agent"`
}

MockConnection represents a WebSocket connection in the mock

type MockConnectionInfo

type MockConnectionInfo struct {
	ConnectionID string `json:"connectionId"`
	ConnectedAt  string `json:"connectedAt"`
	LastActiveAt string `json:"lastActiveAt"`
	SourceIP     string `json:"sourceIp"`
	UserAgent    string `json:"userAgent"`
}

MockConnectionInfo represents connection information returned by GetConnection

type MockDynamORM

type MockDynamORM struct {
	FailOnOperation map[string]error
	Delays          map[string]time.Duration
	// contains filtered or unexported fields
}

MockDynamORM provides a mock implementation of DynamORM for testing Memory optimized for better alignment

func NewMockDynamORM

func NewMockDynamORM() *MockDynamORM

NewMockDynamORM creates a new mock DynamORM instance

func (*MockDynamORM) BeginTransaction

func (m *MockDynamORM) BeginTransaction() (*MockTransaction, error)

BeginTransaction starts a mock transaction

func (*MockDynamORM) Delete

func (m *MockDynamORM) Delete(_ context.Context, table, key string) error

Delete removes an item

func (*MockDynamORM) Get

func (m *MockDynamORM) Get(_ context.Context, table, key string, result any) error

Get retrieves an item by key

func (*MockDynamORM) GetAllData

func (m *MockDynamORM) GetAllData() map[string]map[string]any

GetAllData returns all data for testing inspection

func (*MockDynamORM) Put

func (m *MockDynamORM) Put(_ context.Context, table, key string, item any) error

Put saves an item

func (*MockDynamORM) Query

Query performs a query operation

func (*MockDynamORM) Reset

func (m *MockDynamORM) Reset()

Reset clears all data and resets the mock state

func (*MockDynamORM) WithData

func (m *MockDynamORM) WithData(table, key string, item any) *MockDynamORM

WithData pre-populates the mock with test data

func (*MockDynamORM) WithDelay

func (m *MockDynamORM) WithDelay(operation string, delay time.Duration) *MockDynamORM

WithDelay configures the mock to add delays to operations

func (*MockDynamORM) WithFailure

func (m *MockDynamORM) WithFailure(operation string, err error) *MockDynamORM

WithFailure configures the mock to fail on specific operations

type MockDynamORMWrapper

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

MockDynamORMWrapper wraps MockDynamORM to match the DynamORMWrapper interface

func NewMockDynamORMWrapper

func NewMockDynamORMWrapper(tableName string) *MockDynamORMWrapper

NewMockDynamORMWrapper creates a wrapper that matches DynamORMWrapper interface

func (*MockDynamORMWrapper) BeginTransaction

func (w *MockDynamORMWrapper) BeginTransaction() (any, error)

BeginTransaction starts a mock transaction

func (*MockDynamORMWrapper) Delete

func (w *MockDynamORMWrapper) Delete(ctx context.Context, key any) error

Delete removes an item (matches DynamORMWrapper interface)

func (*MockDynamORMWrapper) Get

func (w *MockDynamORMWrapper) Get(ctx context.Context, key any, result any) error

Get retrieves an item by key (matches DynamORMWrapper interface)

func (*MockDynamORMWrapper) GetAllData

func (w *MockDynamORMWrapper) GetAllData() map[string]map[string]any

GetAllData returns all data for testing inspection

func (*MockDynamORMWrapper) Put

func (w *MockDynamORMWrapper) Put(ctx context.Context, item any) error

Put saves an item (matches DynamORMWrapper interface)

func (*MockDynamORMWrapper) Query

func (w *MockDynamORMWrapper) Query(ctx context.Context, _ any) (any, error)

Query performs a query operation (matches DynamORMWrapper interface)

func (*MockDynamORMWrapper) WithData

func (w *MockDynamORMWrapper) WithData(key string, item any) *MockDynamORMWrapper

WithData pre-populates the mock with test data

func (*MockDynamORMWrapper) WithFailure

func (w *MockDynamORMWrapper) WithFailure(operation string, err error) *MockDynamORMWrapper

WithFailure configures the mock to fail on specific operations

func (*MockDynamORMWrapper) WithTenant

func (w *MockDynamORMWrapper) WithTenant(tenantID string) *MockDynamORMWrapper

WithTenant creates a tenant-scoped wrapper

type MockHTTPClient

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

MockHTTPClient provides a mock HTTP client for external API testing Memory optimized for better alignment

func NewMockHTTPClient

func NewMockHTTPClient() *MockHTTPClient

NewMockHTTPClient creates a new mock HTTP client

func (*MockHTTPClient) Get

func (m *MockHTTPClient) Get(url string) (*MockHTTPResponse, error)

Get simulates an HTTP GET request

func (*MockHTTPClient) Reset

func (m *MockHTTPClient) Reset()

Reset clears all mock state

func (*MockHTTPClient) WithResponse

func (m *MockHTTPClient) WithResponse(url string, response *MockHTTPResponse) *MockHTTPClient

WithResponse configures a response for a URL

type MockHTTPResponse

type MockHTTPResponse struct {
	Headers    map[string]string
	Body       string
	Delay      time.Duration
	StatusCode int
}

MockHTTPResponse represents a mock HTTP response Memory optimized for better alignment

type MockMetricDatum

type MockMetricDatum struct {
	Timestamp  time.Time         `json:"timestamp"`
	Dimensions map[string]string `json:"dimensions,omitempty"`
	Metadata   map[string]any    `json:"metadata,omitempty"`
	MetricName string            `json:"metric_name"`
	Unit       MetricUnit        `json:"unit"`
	Value      float64           `json:"value"`
}

MockMetricDatum represents a single metric data point

type MockTransaction

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

MockTransaction represents a mock DynamORM transaction Memory optimized for better alignment

func (*MockTransaction) Commit

func (tx *MockTransaction) Commit() error

Commit commits the transaction

func (*MockTransaction) Delete

func (tx *MockTransaction) Delete(_ context.Context, table, key string) error

Delete adds a delete operation to the transaction

func (*MockTransaction) Put

func (tx *MockTransaction) Put(_ context.Context, table, key string, item any) error

Put adds a put operation to the transaction

func (*MockTransaction) Rollback

func (tx *MockTransaction) Rollback() error

Rollback rolls back the transaction

type ScenarioRunner

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

ScenarioRunner provides advanced scenario execution capabilities

func NewScenarioRunner

func NewScenarioRunner(app *TestApp) *ScenarioRunner

NewScenarioRunner creates a new scenario runner with advanced capabilities

func (*ScenarioRunner) RunScenariosAdvanced

func (sr *ScenarioRunner) RunScenariosAdvanced(t *testing.T, scenarios []TestScenario)

RunScenariosAdvanced executes scenarios with advanced features

func (*ScenarioRunner) WithParallelExecution

func (sr *ScenarioRunner) WithParallelExecution(enabled bool, maxConcurrency int) *ScenarioRunner

WithParallelExecution configures parallel execution

func (*ScenarioRunner) WithRetry

func (sr *ScenarioRunner) WithRetry(attempts int, delay time.Duration) *ScenarioRunner

WithRetry configures retry behavior

func (*ScenarioRunner) WithTimeouts

func (sr *ScenarioRunner) WithTimeouts(setup, cleanup time.Duration) *ScenarioRunner

WithTimeouts configures timeouts

type Statistic

type Statistic string

Statistic represents CloudWatch statistics

const (
	StatisticSampleCount Statistic = "SampleCount"
	StatisticAverage     Statistic = "Average"
	StatisticSum         Statistic = "Sum"
	StatisticMinimum     Statistic = "Minimum"
	StatisticMaximum     Statistic = "Maximum"
)

type StreamerClientMock added in v1.0.71

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

StreamerClientMock implements the streamer.Client interface for testing.

func NewStreamerClientMock added in v1.0.71

func NewStreamerClientMock() *StreamerClientMock

NewStreamerClientMock creates a new streamer client mock.

func (*StreamerClientMock) DeleteConnection added in v1.0.71

func (m *StreamerClientMock) DeleteConnection(_ context.Context, connectionID string) error

DeleteConnection terminates a WebSocket connection. Implements streamer.Client interface

func (*StreamerClientMock) GetActiveConnections added in v1.0.71

func (m *StreamerClientMock) GetActiveConnections() map[string]*StreamerMockConnection

GetActiveConnections returns all active connections.

func (*StreamerClientMock) GetCallCount added in v1.0.71

func (m *StreamerClientMock) GetCallCount(operation string) int

GetCallCount returns the number of times an operation was called.

func (*StreamerClientMock) GetConnection added in v1.0.71

func (m *StreamerClientMock) GetConnection(_ context.Context, connectionID string) (*streamer.ConnectionInfo, error)

GetConnection retrieves connection information. Implements streamer.Client interface

func (*StreamerClientMock) GetConnectionState added in v1.0.71

func (m *StreamerClientMock) GetConnectionState(connectionID string) *StreamerMockConnection

GetConnectionState returns a copy of the connection state.

func (*StreamerClientMock) GetMessageCount added in v1.0.71

func (m *StreamerClientMock) GetMessageCount(connectionID string) int

GetMessageCount returns the number of messages sent to a connection.

func (*StreamerClientMock) GetMessages added in v1.0.71

func (m *StreamerClientMock) GetMessages(connectionID string) [][]byte

GetMessages returns all messages sent to a connection.

func (*StreamerClientMock) PostToConnection added in v1.0.71

func (m *StreamerClientMock) PostToConnection(_ context.Context, connectionID string, data []byte) error

PostToConnection sends data to a WebSocket connection. Implements streamer.Client interface

func (*StreamerClientMock) Reset added in v1.0.71

func (m *StreamerClientMock) Reset()

Reset clears all mock state.

func (*StreamerClientMock) SimulateConnectionExpiry added in v1.0.71

func (m *StreamerClientMock) SimulateConnectionExpiry()

SimulateConnectionExpiry marks connections as stale based on TTL.

func (*StreamerClientMock) WithConfig added in v1.0.71

WithConfig sets the mock configuration.

func (*StreamerClientMock) WithConnection added in v1.0.71

func (m *StreamerClientMock) WithConnection(connectionID string, conn *StreamerMockConnection) *StreamerClientMock

WithConnection adds a connection to the mock.

func (*StreamerClientMock) WithError added in v1.0.71

func (m *StreamerClientMock) WithError(connectionID string, err error) *StreamerClientMock

WithError configures an error for a specific connection.

func (*StreamerClientMock) WithForbiddenError added in v1.0.71

func (m *StreamerClientMock) WithForbiddenError(connectionID, message string) *StreamerClientMock

WithForbiddenError configures a ForbiddenError for a specific connection.

func (*StreamerClientMock) WithGoneError added in v1.0.71

func (m *StreamerClientMock) WithGoneError(connectionID, message string) *StreamerClientMock

WithGoneError configures a GoneError for a specific connection.

func (*StreamerClientMock) WithInternalServerError added in v1.0.71

func (m *StreamerClientMock) WithInternalServerError(connectionID, message string) *StreamerClientMock

WithInternalServerError configures an InternalServerError for a specific connection.

func (*StreamerClientMock) WithPayloadTooLargeError added in v1.0.71

func (m *StreamerClientMock) WithPayloadTooLargeError(connectionID string, payloadSize, maxSize int, message string) *StreamerClientMock

WithPayloadTooLargeError configures a PayloadTooLargeError for a specific connection.

func (*StreamerClientMock) WithThrottlingError added in v1.0.71

func (m *StreamerClientMock) WithThrottlingError(connectionID string, retryAfter int, message string) *StreamerClientMock

WithThrottlingError configures a ThrottlingError for a specific connection.

type StreamerMockConfig

type StreamerMockConfig struct {
	DefaultSourceIP  string
	DefaultUserAgent string
	ConnectionTTL    int64
	MaxMessageSize   int64
	NetworkDelay     time.Duration
}

StreamerMockConfig configures the behavior of the streamer mock.

func DefaultStreamerMockConfig

func DefaultStreamerMockConfig() *StreamerMockConfig

DefaultStreamerMockConfig returns default configuration for streamer mocks.

type StreamerMockConnection

type StreamerMockConnection struct {
	CreatedTime  time.Time
	Metadata     map[string]any
	ConnectionID string
	ConnectedAt  time.Time
	LastActiveAt time.Time
	SourceIP     string
	UserAgent    string
	State        streamer.ConnectionState
}

StreamerMockConnection represents a WebSocket connection in the mock.

func (*StreamerMockConnection) ToConnectionInfo added in v1.0.71

func (c *StreamerMockConnection) ToConnectionInfo() *streamer.ConnectionInfo

ToConnectionInfo converts a mock connection to a streamer.ConnectionInfo.

type TestApp

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

TestApp represents a test application instance

func NewTestApp

func NewTestApp() *TestApp

NewTestApp creates a new test application with a default Lift app

func (*TestApp) App

func (ta *TestApp) App() *lift.App

App returns the underlying Lift application for configuration

func (*TestApp) ClearHeaders

func (ta *TestApp) ClearHeaders() *TestApp

ClearHeaders clears all headers

func (*TestApp) DELETE

func (ta *TestApp) DELETE(path string) *TestResponse

DELETE performs a DELETE request

func (*TestApp) GET

func (ta *TestApp) GET(path string, query ...map[string]string) *TestResponse

GET performs a GET request with optional query parameters

func (*TestApp) PATCH

func (ta *TestApp) PATCH(path string, body any) *TestResponse

PATCH performs a PATCH request

func (*TestApp) POST

func (ta *TestApp) POST(path string, body any) *TestResponse

POST performs a POST request

func (*TestApp) PUT

func (ta *TestApp) PUT(path string, body any) *TestResponse

PUT performs a PUT request

func (*TestApp) Start

func (ta *TestApp) Start() error

Start starts the test server

func (*TestApp) Stop

func (ta *TestApp) Stop()

Stop stops the test server

func (*TestApp) WithAuth

func (ta *TestApp) WithAuth(auth *AuthConfig) *TestApp

WithAuth sets authentication for subsequent requests

func (*TestApp) WithHeader

func (ta *TestApp) WithHeader(key, value string) *TestApp

WithHeader adds a header for subsequent requests

func (*TestApp) WithHeaders

func (ta *TestApp) WithHeaders(headers map[string]string) *TestApp

WithHeaders adds multiple headers for subsequent requests

type TestResponse

type TestResponse struct {
	Headers    map[string]string
	Body       string
	StatusCode int
	// contains filtered or unexported fields
}

TestResponse provides enhanced assertion capabilities for HTTP responses

func NewTestResponse

func NewTestResponse(t *testing.T, statusCode int, headers map[string]string, body []byte, err error) *TestResponse

NewTestResponse creates a new TestResponse for testing

func (*TestResponse) AssertBodyContains

func (r *TestResponse) AssertBodyContains(substring string) *TestResponse

AssertBodyContains verifies the response body contains a substring

func (*TestResponse) AssertBodyEquals

func (r *TestResponse) AssertBodyEquals(expected string) *TestResponse

AssertBodyEquals verifies the response body exactly matches

func (*TestResponse) AssertError

func (r *TestResponse) AssertError() *TestResponse

AssertError verifies an error occurred

func (*TestResponse) AssertForbidden

func (r *TestResponse) AssertForbidden() *TestResponse

AssertForbidden verifies forbidden response

func (*TestResponse) AssertHasNextPage

func (r *TestResponse) AssertHasNextPage() *TestResponse

AssertHasNextPage verifies next page link exists

func (*TestResponse) AssertHasPrevPage

func (r *TestResponse) AssertHasPrevPage() *TestResponse

AssertHasPrevPage verifies previous page link exists

func (*TestResponse) AssertHeader

func (r *TestResponse) AssertHeader(key, expected string) *TestResponse

AssertHeader verifies a specific header value

func (*TestResponse) AssertHeaderContains

func (r *TestResponse) AssertHeaderContains(key, substring string) *TestResponse

AssertHeaderContains verifies a header contains a substring

func (*TestResponse) AssertHeaderExists

func (r *TestResponse) AssertHeaderExists(key string) *TestResponse

AssertHeaderExists verifies a header exists

func (*TestResponse) AssertJSONPath

func (r *TestResponse) AssertJSONPath(path string, expected any) *TestResponse

AssertJSONPath verifies a JSON path matches expected value

func (*TestResponse) AssertJSONPathCount

func (r *TestResponse) AssertJSONPathCount(path string, expectedCount int) *TestResponse

AssertJSONPathCount verifies the count of items at a JSON path

func (*TestResponse) AssertJSONPathExists

func (r *TestResponse) AssertJSONPathExists(path string) *TestResponse

AssertJSONPathExists verifies a JSON path exists

func (*TestResponse) AssertJSONPathNotExists

func (r *TestResponse) AssertJSONPathNotExists(path string) *TestResponse

AssertJSONPathNotExists verifies a JSON path does not exist

func (*TestResponse) AssertJSONPaths

func (r *TestResponse) AssertJSONPaths(assertions map[string]any) *TestResponse

AssertJSONPaths verifies multiple JSON paths at once

func (*TestResponse) AssertJSONSchema

func (r *TestResponse) AssertJSONSchema(schema map[string]any) *TestResponse

AssertJSONSchema verifies the response matches a JSON schema (basic validation)

func (*TestResponse) AssertNoError

func (r *TestResponse) AssertNoError() *TestResponse

AssertNoError verifies no error occurred

func (*TestResponse) AssertPagination

func (r *TestResponse) AssertPagination(expectedTotal, expectedPage, expectedPerPage int) *TestResponse

AssertPagination verifies pagination metadata

func (*TestResponse) AssertRateLimitExceeded

func (r *TestResponse) AssertRateLimitExceeded() *TestResponse

AssertRateLimitExceeded verifies a rate limit exceeded response

func (*TestResponse) AssertRateLimitHeaders

func (r *TestResponse) AssertRateLimitHeaders() *TestResponse

AssertRateLimitHeaders verifies standard rate limit headers are present

func (*TestResponse) AssertRateLimitLimit

func (r *TestResponse) AssertRateLimitLimit(expected int) *TestResponse

AssertRateLimitLimit verifies the rate limit value

func (*TestResponse) AssertRateLimitRemaining

func (r *TestResponse) AssertRateLimitRemaining(expected int) *TestResponse

AssertRateLimitRemaining verifies the remaining rate limit count

func (*TestResponse) AssertRequiresAuthentication

func (r *TestResponse) AssertRequiresAuthentication() *TestResponse

AssertRequiresAuthentication verifies authentication is required

func (*TestResponse) AssertResponseTime

func (r *TestResponse) AssertResponseTime(_ string) *TestResponse

AssertResponseTime verifies response was fast enough

func (*TestResponse) AssertStatus

func (r *TestResponse) AssertStatus(expected int) *TestResponse

AssertStatus verifies the HTTP status code

func (*TestResponse) AssertTenantIsolation

func (r *TestResponse) AssertTenantIsolation(tenantID string) *TestResponse

AssertTenantIsolation verifies tenant-specific data isolation

func (*TestResponse) AssertUnauthorized

func (r *TestResponse) AssertUnauthorized() *TestResponse

AssertUnauthorized verifies unauthorized response

func (*TestResponse) AssertValidationError

func (r *TestResponse) AssertValidationError(field string) *TestResponse

AssertValidationError verifies a validation error response

func (*TestResponse) AssertValidationErrors

func (r *TestResponse) AssertValidationErrors(fields []string) *TestResponse

AssertValidationErrors verifies multiple validation errors

func (*TestResponse) Chain

func (r *TestResponse) Chain(fn func(*TestResponse)) *TestResponse

Chain allows for custom assertions

func (*TestResponse) Debug

func (r *TestResponse) Debug() *TestResponse

Debug prints the response for debugging

func (*TestResponse) GetBody

func (r *TestResponse) GetBody() string

GetBody returns the response body as string

func (*TestResponse) GetHeader

func (r *TestResponse) GetHeader(key string) string

GetHeader returns a header value

func (*TestResponse) GetJSONPath

func (r *TestResponse) GetJSONPath(path string) any

GetJSONPath extracts a value from the JSON response

func (*TestResponse) GetStatusCode

func (r *TestResponse) GetStatusCode() int

GetStatusCode returns the HTTP status code

func (*TestResponse) IsSuccess

func (r *TestResponse) IsSuccess() bool

IsSuccess returns true if the status code indicates success (2xx)

func (*TestResponse) JSON

func (r *TestResponse) JSON(target any) error

JSON parses the response body as JSON into the provided interface

func (*TestResponse) ParseJSON

func (r *TestResponse) ParseJSON(target any) error

ParseJSON parses the response body as JSON

type TestScenario

type TestScenario struct {
	// Function pointers first (8 bytes each)
	Setup      func(*TestApp) error
	Request    func(*TestApp) *TestResponse
	Assertions func(*testing.T, *TestResponse)
	Cleanup    func(*TestApp) error
	// Strings (16 bytes each)
	Name        string
	Description string
	SkipReason  string
	// Bool last (1 byte)
	Skip bool
}

TestScenario represents a complete test scenario

func AuthenticationScenarios

func AuthenticationScenarios(endpoint string) []TestScenario

AuthenticationScenarios returns common authentication test scenarios

func CRUDScenarios

func CRUDScenarios(basePath string, createData, updateData map[string]any) []TestScenario

CRUDScenarios returns common CRUD operation test scenarios

func ErrorHandlingScenarios

func ErrorHandlingScenarios() []TestScenario

ErrorHandlingScenarios returns error handling test scenarios

func MultiTenantScenarios

func MultiTenantScenarios(endpoint string) []TestScenario

MultiTenantScenarios returns common multi-tenant test scenarios

func PaginationScenarios

func PaginationScenarios(endpoint string, totalItems int) []TestScenario

PaginationScenarios returns pagination test scenarios

func PerformanceScenarios

func PerformanceScenarios(endpoint string, maxResponseTime time.Duration) []TestScenario

PerformanceScenarios returns performance-related test scenarios

func RateLimitingScenarios

func RateLimitingScenarios(endpoint string, limit int) []TestScenario

RateLimitingScenarios returns common rate limiting test scenarios

func ValidationScenarios

func ValidationScenarios(endpoint string, invalidData map[string]any, expectedErrors []string) []TestScenario

ValidationScenarios returns common validation test scenarios

type TransactionOperation

type TransactionOperation struct {
	// Interface first (24 bytes)
	Item any
	// Strings (16 bytes each)
	Type  string
	Table string
	Key   string
}

TransactionOperation represents an operation within a transaction Memory optimized for better alignment

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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