contracttest

package
v3.1.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAllOperationsHaveOperationID

func AssertAllOperationsHaveOperationID(t testing.TB, registry *specs.Registry)

AssertAllOperationsHaveOperationID fails the test when any registered operation lacks operationId.

func AssertOpenAPICompatible

func AssertOpenAPICompatible(t testing.TB, base, head []byte)

AssertOpenAPICompatible fails when head removes or changes base operations in a way that requires compatibility review.

func AssertOperationHasAdminPolicy

func AssertOperationHasAdminPolicy(t testing.TB, registry *specs.Registry, method, path string)

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

func AssertOperationHasTenantPolicy(t testing.TB, registry *specs.Registry, method, path string)

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

func AssertOperationID(t testing.TB, registry *specs.Registry, method, path, operationID string)

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

func AssertSecuritySchemesDefined(t testing.TB, registry *specs.Registry)

AssertSecuritySchemesDefined fails when any operation security requirement references a scheme missing from components.securitySchemes.

func AssertUniqueOperationIDs

func AssertUniqueOperationIDs(t testing.TB, registry *specs.Registry)

AssertUniqueOperationIDs fails the test when two operations share an operationId.

func GoldenOpenAPI

func GoldenOpenAPI(t testing.TB, got, golden []byte)

GoldenOpenAPI fails the test when normalized OpenAPI JSON differs from golden JSON.

func NormalizeOpenAPI

func NormalizeOpenAPI(doc []byte) ([]byte, error)

NormalizeOpenAPI returns deterministic indented JSON for OpenAPI comparison.

func OpenAPICompatibilityFindings

func OpenAPICompatibilityFindings(base, head []byte) ([]string, error)

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

func SecuritySchemeDefinitionFindings(registry *specs.Registry) []string

SecuritySchemeDefinitionFindings returns findings for top-level and operation security requirements that reference schemes missing from components.securitySchemes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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