Documentation
¶
Index ¶
- Constants
- func ConfigureRoutes(r *mux.Router)
- func NewRequestRecorder(method, url string, body io.Reader) (*http.Request, *httptest.ResponseRecorder)
- func NewRouteContext(method, url string, body io.Reader) (routing.RouteContext, *httptest.ResponseRecorder)
- type FakeService
- func (s *FakeService) DeleteTenant(id int32) bool
- func (s *FakeService) GetResource(id int32) (*Resource, bool)
- func (s *FakeService) GetTenant(id int32) (*Tenant, bool)
- func (s *FakeService) ListResources(tenantID int32) []*Resource
- func (s *FakeService) ListTenants() []*Tenant
- func (s *FakeService) PutResource(resource *Resource) *Resource
- func (s *FakeService) PutTenant(tenant *Tenant) *Tenant
- type Page
- type Resource
- type ResourcePage
- type Tenant
- type TestClient
- func (c *TestClient) CreateTenant(ctx context.Context, tenant *Tenant) (*http.Response, error)
- func (c *TestClient) CreateTenantResource(ctx context.Context, tenantID int32, resource *Resource) (*http.Response, error)
- func (c *TestClient) DeleteTenant(ctx context.Context, tenantID int32) (*http.Response, error)
- func (c *TestClient) DeleteTenantResource(ctx context.Context, tenantID, resourceId int32) (*http.Response, error)
- func (c *TestClient) GetResource(ctx context.Context, resourceId int32) (*Resource, *http.Response, error)
- func (c *TestClient) GetTenant(ctx context.Context, tenantID int32) (*Tenant, *http.Response, error)
- func (c *TestClient) GetTenantResource(ctx context.Context, tenantID, resourceId int32) (*Resource, *http.Response, error)
- func (c *TestClient) HeadResource(ctx context.Context, resourceId int32) (*http.Response, error)
- func (c *TestClient) HeadTenant(ctx context.Context, tenantID int32) (*http.Response, error)
- func (c *TestClient) HeadTenantResource(ctx context.Context, tenantID, resourceId int32) (*http.Response, error)
- func (c *TestClient) ListResources(ctx context.Context) ([]Resource, *http.Response, error)
- func (c *TestClient) ListTenantResources(ctx context.Context, tenantID int32) ([]Resource, *http.Response, error)
- func (c *TestClient) ListTenants(ctx context.Context) ([]Tenant, *http.Response, error)
- func (c *TestClient) UpdateTenant(ctx context.Context, tenantID int32, tenant *Tenant) (*http.Response, error)
- func (c *TestClient) UpdateTenantResource(ctx context.Context, tenantID, resourceId int32, resource *Resource) (*http.Response, error)
Constants ¶
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.
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.
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 ¶
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 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 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 ¶
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 (*TestClient) CreateTenantResource ¶
func (*TestClient) DeleteTenant ¶
func (*TestClient) DeleteTenantResource ¶
func (*TestClient) GetResource ¶
func (*TestClient) GetTenantResource ¶
func (*TestClient) HeadResource ¶
func (*TestClient) HeadTenant ¶
func (*TestClient) HeadTenantResource ¶
func (*TestClient) ListResources ¶
Resource Routes
func (*TestClient) ListTenantResources ¶
func (c *TestClient) ListTenantResources(ctx context.Context, tenantID int32) ([]Resource, *http.Response, error)
Tenant Resource Routes
func (*TestClient) ListTenants ¶
Tenant Routes