Service as Consumer and Provider¶
This example demonstrates a common microservice pattern where one service plays both roles in contract testing:
- Provider to a frontend client (
frontend-web → user-service) - Consumer of an upstream auth service (
user-service → auth-service)
Overview¶
- Frontend Client: Consumer-facing client used by
frontend-web - Auth Client: Upstream client used by
user-serviceto callauth-service - User Service: FastAPI app under test (the service in the middle)
- Frontend Consumer Tests: Defines
frontend-web's expectations ofuser-service - Auth Consumer Tests: Defines
user-service's expectations ofauth-service - Provider Verification: Verifies
user-serviceagainst the frontend pact
Use the links above to view detailed documentation within each file.
What This Example Demonstrates¶
- One service owning two separate contracts in opposite directions
- Consumer tests for each dependency boundary
- Provider verification with state handlers that model upstream
auth-servicebehaviour without needing it to run - A
Protocol-based seam that allows the real FastAPI application to run during verification while the upstream dependency is replaced in-process