Documentation
¶
Overview ¶
Package contracttest provides testing helpers for API contract drift checks.
The helpers assert route contract coverage, OpenAPI operation metadata, stable operation identity, scoped security requirements, typed route policy metadata, Problem Details response sets, typed problem catalogs, deterministic OpenAPI golden output, and conservative operation, policy, security-scheme, inherited global-security, inline schema, and component schema compatibility in application tests.
Index ¶
- func AssertAllOperationsHaveOperationID(t testing.TB, registry *specs.Registry)
- func AssertOpenAPICompatible(t testing.TB, base, head []byte)
- func AssertOperationHasAdminPolicy(t testing.TB, registry *specs.Registry, method, path string)
- func AssertOperationHasAdminPolicyNamed(t testing.TB, registry *specs.Registry, method, path, policy string)
- func AssertOperationHasIdempotencyPolicy(t testing.TB, registry *specs.Registry, method, path string)
- func AssertOperationHasIdempotencyPolicyHeader(t testing.TB, registry *specs.Registry, method, path, header string)
- func AssertOperationHasProblemResponse(t testing.TB, registry *specs.Registry, method, path string, status int)
- func AssertOperationHasProblemResponses(t testing.TB, registry *specs.Registry, method, path string, statuses ...int)
- func AssertOperationHasRateLimitPolicy(t testing.TB, registry *specs.Registry, method, path, policy string)
- func AssertOperationHasResponse(t testing.TB, registry *specs.Registry, method, path string, status int)
- func AssertOperationHasSecurity(t testing.TB, registry *specs.Registry, method, path, scheme string)
- func AssertOperationHasSecurityScopes(t testing.TB, registry *specs.Registry, method, path, scheme string, ...)
- func AssertOperationHasTenantPolicy(t testing.TB, registry *specs.Registry, method, path string)
- func AssertOperationHasTenantPolicySource(t testing.TB, registry *specs.Registry, method, path, source string)
- func AssertOperationID(t testing.TB, registry *specs.Registry, method, path, operationID string)
- func AssertProblemCatalogHas(t testing.TB, catalog *httpx.ProblemCatalog, code httpx.ProblemCode)
- func AssertRegistryValid(t testing.TB, registry *routecontracts.Registry)
- func AssertRouteCoverage(t testing.TB, registry *routecontracts.Registry, method, pattern string)
- func AssertSecuritySchemesDefined(t testing.TB, registry *specs.Registry)
- func AssertUniqueOperationIDs(t testing.TB, registry *specs.Registry)
- func GoldenOpenAPI(t testing.TB, got, golden []byte)
- func NormalizeOpenAPI(doc []byte) ([]byte, error)
- func OpenAPICompatibilityFindings(base, head []byte) ([]string, error)
- func SecuritySchemeDefinitionFindings(registry *specs.Registry) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertAllOperationsHaveOperationID ¶
AssertAllOperationsHaveOperationID fails the test when any registered operation lacks operationId.
func AssertOpenAPICompatible ¶
AssertOpenAPICompatible fails when head removes or changes base operations in a way that requires compatibility review.
func AssertOperationHasAdminPolicy ¶
AssertOperationHasAdminPolicy fails when an operation lacks admin policy metadata.
func AssertOperationHasAdminPolicyNamed ¶
func AssertOperationHasAdminPolicyNamed(t testing.TB, registry *specs.Registry, method, path, policy string)
AssertOperationHasAdminPolicyNamed fails when an operation lacks the expected admin policy metadata.
func AssertOperationHasIdempotencyPolicy ¶
func AssertOperationHasIdempotencyPolicy(t testing.TB, registry *specs.Registry, method, path string)
AssertOperationHasIdempotencyPolicy fails when an operation lacks idempotency metadata.
func AssertOperationHasIdempotencyPolicyHeader ¶
func AssertOperationHasIdempotencyPolicyHeader(t testing.TB, registry *specs.Registry, method, path, header string)
AssertOperationHasIdempotencyPolicyHeader fails when an operation lacks required idempotency metadata with the expected header.
func AssertOperationHasProblemResponse ¶
func AssertOperationHasProblemResponse(t testing.TB, registry *specs.Registry, method, path string, status int)
AssertOperationHasProblemResponse fails when an operation response is not application/problem+json.
func AssertOperationHasProblemResponses ¶
func AssertOperationHasProblemResponses(t testing.TB, registry *specs.Registry, method, path string, statuses ...int)
AssertOperationHasProblemResponses fails when an operation lacks documented Problem Details responses for any expected status.
func AssertOperationHasRateLimitPolicy ¶
func AssertOperationHasRateLimitPolicy(t testing.TB, registry *specs.Registry, method, path, policy string)
AssertOperationHasRateLimitPolicy fails when an operation lacks the expected rate-limit policy metadata.
func AssertOperationHasResponse ¶
func AssertOperationHasResponse(t testing.TB, registry *specs.Registry, method, path string, status int)
AssertOperationHasResponse fails the test when an OpenAPI operation lacks a response status.
func AssertOperationHasSecurity ¶
func AssertOperationHasSecurity(t testing.TB, registry *specs.Registry, method, path, scheme string)
AssertOperationHasSecurity fails the test when an OpenAPI operation lacks a security requirement.
func AssertOperationHasSecurityScopes ¶
func AssertOperationHasSecurityScopes(t testing.TB, registry *specs.Registry, method, path, scheme string, scopes ...string)
AssertOperationHasSecurityScopes fails the test when an OpenAPI operation lacks the expected security requirement scopes for a scheme.
func AssertOperationHasTenantPolicy ¶
AssertOperationHasTenantPolicy fails when an operation lacks required tenant metadata.
func AssertOperationHasTenantPolicySource ¶
func AssertOperationHasTenantPolicySource(t testing.TB, registry *specs.Registry, method, path, source string)
AssertOperationHasTenantPolicySource fails when an operation lacks required tenant metadata with the expected source.
func AssertOperationID ¶
AssertOperationID fails the test when an OpenAPI operation lacks the expected operationId.
func AssertProblemCatalogHas ¶
func AssertProblemCatalogHas(t testing.TB, catalog *httpx.ProblemCatalog, code httpx.ProblemCode)
AssertProblemCatalogHas fails the test when a problem catalog lacks a code.
func AssertRegistryValid ¶
func AssertRegistryValid(t testing.TB, registry *routecontracts.Registry)
AssertRegistryValid fails the test when a route contract registry has coverage errors.
func AssertRouteCoverage ¶
func AssertRouteCoverage(t testing.TB, registry *routecontracts.Registry, method, pattern string)
AssertRouteCoverage fails the test when method and pattern are not registered.
func AssertSecuritySchemesDefined ¶
AssertSecuritySchemesDefined fails when any operation security requirement references a scheme missing from components.securitySchemes.
func AssertUniqueOperationIDs ¶
AssertUniqueOperationIDs fails the test when two operations share an operationId.
func GoldenOpenAPI ¶
GoldenOpenAPI fails the test when normalized OpenAPI JSON differs from golden JSON.
func NormalizeOpenAPI ¶
NormalizeOpenAPI returns deterministic indented JSON for OpenAPI comparison.
func OpenAPICompatibilityFindings ¶
OpenAPICompatibilityFindings reports conservative compatibility findings between two OpenAPI JSON documents. Additive operations and responses are compatible; removed operations, changed operation IDs, removed documented parameters, added required parameters, removed documented responses, request-body tightening or content removal, response content removal, and changed security requirements or security scheme definitions are findings. Tenant, idempotency, rate-limit, admin, deprecation/sunset route policy drift, and obvious inline or component schema removals or narrowing are findings too.
func SecuritySchemeDefinitionFindings ¶
SecuritySchemeDefinitionFindings returns findings for top-level and operation security requirements that reference schemes missing from components.securitySchemes.
Types ¶
This section is empty.