Documentation
¶
Overview ¶
Package harness provides API client utilities for integration testing
Package harness provides integration test utilities for the Lesser project
Index ¶
- type APIClient
- func (c *APIClient) DELETE(path string, params ...map[string]string) *APIResponse
- func (c *APIClient) GET(path string, params ...map[string]string) *APIResponse
- func (c *APIClient) PATCH(path string, body interface{}, params ...map[string]string) *APIResponse
- func (c *APIClient) POST(path string, body interface{}, params ...map[string]string) *APIResponse
- func (c *APIClient) PUT(path string, body interface{}, params ...map[string]string) *APIResponse
- func (c *APIClient) WithToken(token string) *APIClient
- type APIResponse
- type ActivityPubClient
- func (c *ActivityPubClient) GetActor(username string) *APIResponse
- func (c *ActivityPubClient) GetFollowers(username string, params map[string]string) *APIResponse
- func (c *ActivityPubClient) GetFollowing(username string, params map[string]string) *APIResponse
- func (c *ActivityPubClient) GetInbox(username string, params map[string]string) *APIResponse
- func (c *ActivityPubClient) GetNodeInfo() *APIResponse
- func (c *ActivityPubClient) GetOutbox(username string, params map[string]string) *APIResponse
- func (c *ActivityPubClient) PostToInbox(username string, activity interface{}) *APIResponse
- func (c *ActivityPubClient) Webfinger(resource string) *APIResponse
- type CleanupMode
- type CostOperation
- type CostTracker
- type IntegrationTestHarness
- func (h *IntegrationTestHarness) AssertActivityPubResponse(resp *http.Response, expectedStatus int)
- func (h *IntegrationTestHarness) AssertCostBudget(maxRCU, maxWCU float64)
- func (h *IntegrationTestHarness) Config() *TestConfig
- func (h *IntegrationTestHarness) Context() context.Context
- func (h *IntegrationTestHarness) CostTracker() *CostTracker
- func (h *IntegrationTestHarness) CreateTestActivity(actorID string, activityType string) *activitypub.Activity
- func (h *IntegrationTestHarness) CreateTestActor(username string) *activitypub.Actor
- func (h *IntegrationTestHarness) GetSeededActors() []*activitypub.Actor
- func (h *IntegrationTestHarness) GetSeededStatuses() []*TestStatus
- func (h *IntegrationTestHarness) GetSeededUsers() []*TestUser
- func (h *IntegrationTestHarness) GetServerURL() string
- func (h *IntegrationTestHarness) InjectError(errorRate float64, latency time.Duration)
- func (h *IntegrationTestHarness) Logger() *zap.Logger
- func (h *IntegrationTestHarness) MakeRequest(method, path string, _ interface{}, headers map[string]string) *http.Response
- func (h *IntegrationTestHarness) RepositoryStorage() *mocks.EnhancedMockStorage
- func (h *IntegrationTestHarness) ResetErrorInjection()
- func (h *IntegrationTestHarness) StartServer(handler http.Handler)
- func (h *IntegrationTestHarness) Storage() *mocks.EnhancedMockStorage
- func (h *IntegrationTestHarness) TestStorage() *mocks.EnhancedMockStorage
- func (h *IntegrationTestHarness) WaitForCondition(condition func() bool, timeout time.Duration, message string)
- type MastodonAPIClient
- func (c *MastodonAPIClient) CreateStatus(status map[string]interface{}) *APIResponse
- func (c *MastodonAPIClient) DeleteStatus(statusID string) *APIResponse
- func (c *MastodonAPIClient) FollowAccount(accountID string) *APIResponse
- func (c *MastodonAPIClient) GetAccount(accountID string) *APIResponse
- func (c *MastodonAPIClient) GetHomeTimeline(params map[string]string) *APIResponse
- func (c *MastodonAPIClient) GetNotifications(params map[string]string) *APIResponse
- func (c *MastodonAPIClient) GetStatus(statusID string) *APIResponse
- func (c *MastodonAPIClient) UnfollowAccount(accountID string) *APIResponse
- func (c *MastodonAPIClient) VerifyCredentials() *APIResponse
- type TestAssertions
- func (a *TestAssertions) AssertActivityPubResponse(resp *APIResponse, v interface{})
- func (a *TestAssertions) AssertErrorResponse(resp *APIResponse, expectedStatus int, expectedError string)
- func (a *TestAssertions) AssertJSONResponse(resp *APIResponse, v interface{})
- func (a *TestAssertions) AssertStatusCode(resp *APIResponse, expected int)
- type TestConfig
- type TestStatus
- type TestUser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIClient ¶
type APIClient struct {
BaseURL string
HTTPClient *http.Client
Token string
// contains filtered or unexported fields
}
APIClient provides a testing-focused HTTP client for making requests to the Lesser API
func NewAPIClient ¶
NewAPIClient creates a new API client for testing
func (*APIClient) DELETE ¶
func (c *APIClient) DELETE(path string, params ...map[string]string) *APIResponse
DELETE makes a DELETE request
func (*APIClient) GET ¶
func (c *APIClient) GET(path string, params ...map[string]string) *APIResponse
GET makes a GET request to the specified path
func (*APIClient) PATCH ¶
func (c *APIClient) PATCH(path string, body interface{}, params ...map[string]string) *APIResponse
PATCH makes a PATCH request with JSON body
func (*APIClient) POST ¶
func (c *APIClient) POST(path string, body interface{}, params ...map[string]string) *APIResponse
POST makes a POST request with JSON body
type APIResponse ¶
APIResponse represents a standardized API response for testing
func (*APIResponse) JSON ¶
func (r *APIResponse) JSON(v interface{}) error
JSON unmarshals the response body into the provided interface
func (*APIResponse) String ¶
func (r *APIResponse) String() string
String returns the response body as a string
type ActivityPubClient ¶
type ActivityPubClient struct {
*APIClient
}
ActivityPubClient provides ActivityPub-specific API methods
func NewActivityPubClient ¶
func NewActivityPubClient(t *testing.T, baseURL string) *ActivityPubClient
NewActivityPubClient creates a client configured for ActivityPub endpoints
func (*ActivityPubClient) GetActor ¶
func (c *ActivityPubClient) GetActor(username string) *APIResponse
GetActor retrieves an ActivityPub actor
func (*ActivityPubClient) GetFollowers ¶
func (c *ActivityPubClient) GetFollowers(username string, params map[string]string) *APIResponse
GetFollowers retrieves an actor's followers
func (*ActivityPubClient) GetFollowing ¶
func (c *ActivityPubClient) GetFollowing(username string, params map[string]string) *APIResponse
GetFollowing retrieves who an actor is following
func (*ActivityPubClient) GetInbox ¶
func (c *ActivityPubClient) GetInbox(username string, params map[string]string) *APIResponse
GetInbox retrieves an actor's inbox (requires authentication)
func (*ActivityPubClient) GetNodeInfo ¶
func (c *ActivityPubClient) GetNodeInfo() *APIResponse
GetNodeInfo retrieves NodeInfo
func (*ActivityPubClient) GetOutbox ¶
func (c *ActivityPubClient) GetOutbox(username string, params map[string]string) *APIResponse
GetOutbox retrieves an actor's outbox
func (*ActivityPubClient) PostToInbox ¶
func (c *ActivityPubClient) PostToInbox(username string, activity interface{}) *APIResponse
PostToInbox posts an activity to an inbox
func (*ActivityPubClient) Webfinger ¶
func (c *ActivityPubClient) Webfinger(resource string) *APIResponse
Webfinger performs a WebFinger lookup
type CleanupMode ¶
type CleanupMode int
CleanupMode defines how test data should be cleaned up
const ( // CleanupNone disables automatic cleanup of test data CleanupNone CleanupMode = iota // CleanupOnSuccess cleans up test data only if test passes CleanupOnSuccess // CleanupAlways cleans up test data regardless of test outcome CleanupAlways )
type CostOperation ¶
CostOperation represents a single tracked operation
type CostTracker ¶
type CostTracker struct {
// contains filtered or unexported fields
}
CostTracker tracks DynamoDB read/write capacity unit usage for testing
func NewCostTracker ¶
func NewCostTracker() *CostTracker
NewCostTracker creates a new cost tracker instance
func (*CostTracker) GetOperations ¶
func (c *CostTracker) GetOperations() []CostOperation
GetOperations returns all tracked operations
func (*CostTracker) GetTotalCost ¶
func (c *CostTracker) GetTotalCost() (rcu, wcu float64)
GetTotalCost returns the total RCU and WCU consumed
func (*CostTracker) Reset ¶
func (c *CostTracker) Reset()
Reset clears all tracked operations and totals
func (*CostTracker) TrackOperation ¶
func (c *CostTracker) TrackOperation(name string, rcu, wcu float64)
TrackOperation records a DynamoDB operation's cost
type IntegrationTestHarness ¶
type IntegrationTestHarness struct {
// contains filtered or unexported fields
}
IntegrationTestHarness provides a complete testing environment for integration tests
func NewIntegrationTestHarness ¶
func NewIntegrationTestHarness(t *testing.T, config *TestConfig) *IntegrationTestHarness
NewIntegrationTestHarness creates a new integration test harness
func (*IntegrationTestHarness) AssertActivityPubResponse ¶
func (h *IntegrationTestHarness) AssertActivityPubResponse(resp *http.Response, expectedStatus int)
AssertActivityPubResponse validates an ActivityPub HTTP response
func (*IntegrationTestHarness) AssertCostBudget ¶
func (h *IntegrationTestHarness) AssertCostBudget(maxRCU, maxWCU float64)
AssertCostBudget asserts that the tracked costs are within the specified budget
func (*IntegrationTestHarness) Config ¶
func (h *IntegrationTestHarness) Config() *TestConfig
Config returns the test configuration
func (*IntegrationTestHarness) Context ¶
func (h *IntegrationTestHarness) Context() context.Context
Context returns the test context
func (*IntegrationTestHarness) CostTracker ¶
func (h *IntegrationTestHarness) CostTracker() *CostTracker
CostTracker returns the cost tracker instance
func (*IntegrationTestHarness) CreateTestActivity ¶
func (h *IntegrationTestHarness) CreateTestActivity(actorID string, activityType string) *activitypub.Activity
CreateTestActivity creates a test activity and stores it for cleanup
func (*IntegrationTestHarness) CreateTestActor ¶
func (h *IntegrationTestHarness) CreateTestActor(username string) *activitypub.Actor
CreateTestActor creates a test actor and stores it for cleanup
func (*IntegrationTestHarness) GetSeededActors ¶
func (h *IntegrationTestHarness) GetSeededActors() []*activitypub.Actor
GetSeededActors returns pre-seeded test actors
func (*IntegrationTestHarness) GetSeededStatuses ¶
func (h *IntegrationTestHarness) GetSeededStatuses() []*TestStatus
GetSeededStatuses returns pre-seeded test statuses
func (*IntegrationTestHarness) GetSeededUsers ¶
func (h *IntegrationTestHarness) GetSeededUsers() []*TestUser
GetSeededUsers returns pre-seeded test users
func (*IntegrationTestHarness) GetServerURL ¶
func (h *IntegrationTestHarness) GetServerURL() string
GetServerURL returns the test server URL
func (*IntegrationTestHarness) InjectError ¶
func (h *IntegrationTestHarness) InjectError(errorRate float64, latency time.Duration)
InjectError sets the error rate and latency for simulating failures
func (*IntegrationTestHarness) Logger ¶
func (h *IntegrationTestHarness) Logger() *zap.Logger
Logger returns the test logger
func (*IntegrationTestHarness) MakeRequest ¶
func (h *IntegrationTestHarness) MakeRequest(method, path string, _ interface{}, headers map[string]string) *http.Response
MakeRequest makes an HTTP request to the test server Note: body parameter will be used for POST/PUT request payloads
func (*IntegrationTestHarness) RepositoryStorage ¶
func (h *IntegrationTestHarness) RepositoryStorage() *mocks.EnhancedMockStorage
RepositoryStorage returns the storage instance for repository-level access
func (*IntegrationTestHarness) ResetErrorInjection ¶
func (h *IntegrationTestHarness) ResetErrorInjection()
ResetErrorInjection clears any error injection settings
func (*IntegrationTestHarness) StartServer ¶
func (h *IntegrationTestHarness) StartServer(handler http.Handler)
StartServer starts a test HTTP server with the given app
func (*IntegrationTestHarness) Storage ¶
func (h *IntegrationTestHarness) Storage() *mocks.EnhancedMockStorage
Storage returns the storage instance
func (*IntegrationTestHarness) TestStorage ¶
func (h *IntegrationTestHarness) TestStorage() *mocks.EnhancedMockStorage
TestStorage returns the storage instance for test-level access (alias for compatibility)
func (*IntegrationTestHarness) WaitForCondition ¶
func (h *IntegrationTestHarness) WaitForCondition(condition func() bool, timeout time.Duration, message string)
WaitForCondition waits for a condition to be true with a timeout
type MastodonAPIClient ¶
type MastodonAPIClient struct {
*APIClient
}
MastodonAPIClient provides Mastodon-specific API methods
func NewMastodonAPIClient ¶
func NewMastodonAPIClient(t *testing.T, baseURL string) *MastodonAPIClient
NewMastodonAPIClient creates a client configured for Mastodon API endpoints
func (*MastodonAPIClient) CreateStatus ¶
func (c *MastodonAPIClient) CreateStatus(status map[string]interface{}) *APIResponse
CreateStatus creates a new status/post
func (*MastodonAPIClient) DeleteStatus ¶
func (c *MastodonAPIClient) DeleteStatus(statusID string) *APIResponse
DeleteStatus deletes a status by ID
func (*MastodonAPIClient) FollowAccount ¶
func (c *MastodonAPIClient) FollowAccount(accountID string) *APIResponse
FollowAccount follows an account
func (*MastodonAPIClient) GetAccount ¶
func (c *MastodonAPIClient) GetAccount(accountID string) *APIResponse
GetAccount retrieves account information by ID
func (*MastodonAPIClient) GetHomeTimeline ¶
func (c *MastodonAPIClient) GetHomeTimeline(params map[string]string) *APIResponse
GetHomeTimeline retrieves the home timeline
func (*MastodonAPIClient) GetNotifications ¶
func (c *MastodonAPIClient) GetNotifications(params map[string]string) *APIResponse
GetNotifications retrieves notifications
func (*MastodonAPIClient) GetStatus ¶
func (c *MastodonAPIClient) GetStatus(statusID string) *APIResponse
GetStatus retrieves a status by ID
func (*MastodonAPIClient) UnfollowAccount ¶
func (c *MastodonAPIClient) UnfollowAccount(accountID string) *APIResponse
UnfollowAccount unfollows an account
func (*MastodonAPIClient) VerifyCredentials ¶
func (c *MastodonAPIClient) VerifyCredentials() *APIResponse
VerifyCredentials verifies the current user's credentials
type TestAssertions ¶
type TestAssertions struct {
// contains filtered or unexported fields
}
TestAssertions provides common test assertions for API responses
func NewTestAssertions ¶
func NewTestAssertions(t *testing.T) *TestAssertions
NewTestAssertions creates a new test assertions helper
func (*TestAssertions) AssertActivityPubResponse ¶
func (a *TestAssertions) AssertActivityPubResponse(resp *APIResponse, v interface{})
AssertActivityPubResponse asserts the response is a valid ActivityPub response
func (*TestAssertions) AssertErrorResponse ¶
func (a *TestAssertions) AssertErrorResponse(resp *APIResponse, expectedStatus int, expectedError string)
AssertErrorResponse asserts the response contains an error with expected properties
func (*TestAssertions) AssertJSONResponse ¶
func (a *TestAssertions) AssertJSONResponse(resp *APIResponse, v interface{})
AssertJSONResponse asserts the response is valid JSON and unmarshals it
func (*TestAssertions) AssertStatusCode ¶
func (a *TestAssertions) AssertStatusCode(resp *APIResponse, expected int)
AssertStatusCode asserts the response has the expected status code
type TestConfig ¶
type TestConfig struct {
Domain string
TableName string
UseMemory bool
LogLevel zapcore.Level
ServerTimeout time.Duration
CleanupMode CleanupMode
// Enhanced harness configuration
UseDynamORM bool // Whether to use DynamORM-backed storage
UseEnhanced bool // Whether to use enhanced mock storage
SeedData bool // Whether to seed initial test data
ErrorInjection bool // Whether to enable error injection capabilities
CostTracking bool // Whether to track DynamoDB cost units
LatencyMode time.Duration // Artificial latency to inject into operations
ErrorRate float64 // Probability (0.0-1.0) that operations will fail
}
TestConfig holds configuration for integration tests
func DefaultTestConfig ¶
func DefaultTestConfig() *TestConfig
DefaultTestConfig returns default configuration for integration tests