ProviderHarness, a mock runtime that lets you test resources without connecting to production infrastructure.
Prerequisites
Your provider project should have pytest configured:ProviderHarness
ProviderHarness simulates the runtime environment, letting you invoke lifecycle methods directly:
LifecycleResult
Each invoke method returns aLifecycleResult with:
| Attribute | Type | Description |
|---|---|---|
success | bool | Whether the lifecycle method succeeded |
failed | bool | Opposite of success (convenience property) |
outputs | Outputs | None | Returned outputs on success |
error | Exception | None | Captured exception on failure |
resource | Resource | The resource instance used |
Testing Create
Testing Update
Pass both the new config and the previous config:Testing Delete
Testing Failures
Verify that your resource rejects invalid configurations:Mocking External Services
Most providers interact with external APIs. Use pytest’smonkeypatch fixture to replace API clients with mocks.
Mock Setup with conftest.py
Create reusable fixtures intests/conftest.py:
Using Mocks in Tests
Mocking GCP Services
For GCP providers, mock the service client and credentials:Testing Idempotency
Verify your lifecycle methods handle retry scenarios correctly.Create Idempotency
Test thaton_create handles “already exists” errors:
Delete Idempotency
Test thaton_delete handles “not found” errors: