testsupport

package
v0.0.1-alpha.134 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIBase               = "/api/v1"
	APIResources          = APIBase + "/resources/"
	APIResourceByID       = APIBase + "/resources/%d"
	APIResourceMetadata   = APIBase + "/resources/%d/metadata"
	APITenants            = APIBase + "/tenants/"
	APITenantByID         = APIBase + "/tenants/%d"
	APITenantResources    = APIBase + "/tenants/%d/resources"
	APITenantResourceByID = APIBase + "/tenants/%d/resources/%d"
	APIHeadersEcho        = APIBase + "/headers/echo"
	APIFormSubmit         = APIBase + "/form/submit"
	APIItemsUUID          = APIBase + "/items/%s/uuid"
)

Common API paths used by integration tests. Centralizing them here reduces duplication and makes it easier to update paths in one place.

View Source
const (
	APIPrefix       = "/api/v1"
	WSPath          = "/ws"
	ResourcesPath   = "/resources"
	ResourcesBulk   = "/resources/bulk"
	ResourcesSearch = "/resources/search"
	ResourceMeta    = "/resources/{resourceId}/metadata"
	ResourceIDPath  = "/resources/{resourceId}"
	ItemsUUIDPath   = "/items/{itemId}/uuid"
	HeadersEchoPath = "/headers/echo"
	FilterPath      = "/filter"
	FormSubmitPath  = "/form/submit"
	TenantsPath     = "/tenants"
	TenantIDPath    = "/tenants/{tenantID}"
	TenantResources = "/tenants/{tenantID}/resources"

	ParamResourceID = "resourceId"
	ParamTenantID   = "tenantID"
	ParamItemID     = "itemId"

	TagResources = "Resources"
	TagTenants   = "Tenants"
	TagMisc      = "Misc"
	TagItems     = "Items"
)

Constants to avoid repeating string literals throughout the test routes.

View Source
const (
	ErrInvalidResourceID = "Invalid ResourceID"
	ErrParseResourceID   = "Failed to parse resource id."
	ErrBadRequest        = "Bad Request"
	ErrInvalidTenantID   = "Invalid TenantID"
	ErrTenantMissing     = "tenantID missing or invalid"
)

Variables

This section is empty.

Functions

func ConfigureRoutes

func ConfigureRoutes(r *mux.Router)

ConfigureRoutes registers a broad set of routes used by unit and integration tests. These routes exercise many RouteContext features and edge-cases so the test-suite can validate behavior and OpenAPI generation.

func NewRequestRecorder

func NewRequestRecorder(method, url string, body io.Reader) (*http.Request, *httptest.ResponseRecorder)

NewRequestRecorder creates an http.Request and ResponseRecorder for tests. This is the preferred test helper - it delegates to testhelpers for the implementation.

func NewRouteContext

func NewRouteContext(method, url string, body io.Reader) (routing.RouteContext, *httptest.ResponseRecorder)

NewRouteContext creates a routing.RouteContext and returns it along with the underlying ResponseRecorder for assertions. This is the preferred test helper - it delegates to testhelpers for the implementation.

Types

type FakeService

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

FakeService is a struct to hold our in-memory "database" and mock methods.

var Service *FakeService = NewFakeService()

func NewFakeService

func NewFakeService() *FakeService

NewFakeService creates and returns a new instance of MockService.

func (*FakeService) DeleteTenant

func (s *FakeService) DeleteTenant(id int32) bool

DeleteTenant removes a tenant if it exists and returns true when deleted.

func (*FakeService) GetResource

func (s *FakeService) GetResource(id int32) (*Resource, bool)

GetResource retrieves a Resource by ID.

func (*FakeService) GetTenant

func (s *FakeService) GetTenant(id int32) (*Tenant, bool)

GetTenant retrieves a Tenant by ID.

func (*FakeService) ListResources

func (s *FakeService) ListResources(tenantID int32) []*Resource

ListResources returns all Resources.

func (*FakeService) ListTenants

func (s *FakeService) ListTenants() []*Tenant

ListTenants returns all Tenants.

func (*FakeService) PutResource

func (s *FakeService) PutResource(resource *Resource) *Resource

PutResource adds or updates a Resource.

func (*FakeService) PutTenant

func (s *FakeService) PutTenant(tenant *Tenant) *Tenant

PutTenant adds or updates a Tenant.

type Page

type Page[T any] struct {
	Next   uuid.UUID
	Models []T
}

type Resource

type Resource struct {
	TenantID   int32     `json:"tenant_id"`
	ResourceID int32     `json:"resource_id"`
	Name       string    `json:"name"`
	Type       string    `json:"type"`
	CreatedAt  time.Time `json:"created_at"`
}

Resource represents a resource owned by a tenant.

type ResourcePage

type ResourcePage struct {
	Next   uuid.UUID
	Models []Resource
}

type Tenant

type Tenant struct {
	TenantID  int32     `json:"tenant_id"`
	Name      string    `json:"name"`
	Plan      string    `json:"plan"`
	CreatedAt time.Time `json:"created_at"`
}

Tenant represents a tenant in the system.

type TestClient

type TestClient struct {
	BaseURL    string
	HTTPClient *http.Client
}

TestClient encapsulates the client and base URL

func NewTestClient

func NewTestClient(baseURL string) *TestClient

NewTestClient creates a new HTTP client instance

func (*TestClient) CreateTenant

func (c *TestClient) CreateTenant(ctx context.Context, tenant *Tenant) (*http.Response, error)

func (*TestClient) CreateTenantResource

func (c *TestClient) CreateTenantResource(ctx context.Context, tenantID int32, resource *Resource) (*http.Response, error)

func (*TestClient) DeleteTenant

func (c *TestClient) DeleteTenant(ctx context.Context, tenantID int32) (*http.Response, error)

func (*TestClient) DeleteTenantResource

func (c *TestClient) DeleteTenantResource(ctx context.Context, tenantID, resourceId int32) (*http.Response, error)

func (*TestClient) GetResource

func (c *TestClient) GetResource(ctx context.Context, resourceId int32) (*Resource, *http.Response, error)

func (*TestClient) GetTenant

func (c *TestClient) GetTenant(ctx context.Context, tenantID int32) (*Tenant, *http.Response, error)

func (*TestClient) GetTenantResource

func (c *TestClient) GetTenantResource(ctx context.Context, tenantID, resourceId int32) (*Resource, *http.Response, error)

func (*TestClient) HeadResource

func (c *TestClient) HeadResource(ctx context.Context, resourceId int32) (*http.Response, error)

func (*TestClient) HeadTenant

func (c *TestClient) HeadTenant(ctx context.Context, tenantID int32) (*http.Response, error)

func (*TestClient) HeadTenantResource

func (c *TestClient) HeadTenantResource(ctx context.Context, tenantID, resourceId int32) (*http.Response, error)

func (*TestClient) ListResources

func (c *TestClient) ListResources(ctx context.Context) ([]Resource, *http.Response, error)

Resource Routes

func (*TestClient) ListTenantResources

func (c *TestClient) ListTenantResources(ctx context.Context, tenantID int32) ([]Resource, *http.Response, error)

Tenant Resource Routes

func (*TestClient) ListTenants

func (c *TestClient) ListTenants(ctx context.Context) ([]Tenant, *http.Response, error)

Tenant Routes

func (*TestClient) UpdateTenant

func (c *TestClient) UpdateTenant(ctx context.Context, tenantID int32, tenant *Tenant) (*http.Response, error)

func (*TestClient) UpdateTenantResource

func (c *TestClient) UpdateTenantResource(ctx context.Context, tenantID, resourceId int32, resource *Resource) (*http.Response, error)

Jump to

Keyboard shortcuts

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