harness

package
v1.1.17 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package harness provides API client utilities for integration testing

Package harness provides integration test utilities for the Lesser project

Index

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

func NewAPIClient(t *testing.T, baseURL string) *APIClient

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

func (*APIClient) PUT

func (c *APIClient) PUT(path string, body interface{}, params ...map[string]string) *APIResponse

PUT makes a PUT request with JSON body

func (*APIClient) WithToken

func (c *APIClient) WithToken(token string) *APIClient

WithToken sets the authorization token for API requests

type APIResponse

type APIResponse struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
	Response   *http.Response
}

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

type CostOperation struct {
	Name      string
	RCU       float64
	WCU       float64
	Timestamp time.Time
}

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

Storage returns the storage instance

func (*IntegrationTestHarness) TestStorage

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

type TestStatus

type TestStatus struct {
	ID         string
	AuthorID   string
	Content    string
	Visibility string
	CreatedAt  time.Time
}

TestStatus represents a simplified status for testing purposes

type TestUser

type TestUser struct {
	ID          string
	Username    string
	DisplayName string
	ActorID     string
	CreatedAt   time.Time
}

TestUser represents a simplified user for testing purposes

Jump to

Keyboard shortcuts

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