Skip to main content
Testing providers before deployment catches bugs early and ensures your lifecycle methods behave correctly. The SDK provides 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 a LifecycleResult with:

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’s monkeypatch fixture to replace API clients with mocks.

Mock Setup with conftest.py

Create reusable fixtures in tests/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 that on_create handles “already exists” errors:

Delete Idempotency

Test that on_delete handles “not found” errors:

Testing Configuration Scenarios

Test different configuration combinations and edge cases.

Valid Configurations

Credentials as String or Dict

Some configurations accept credentials as either a dict or JSON string:

Tracking Test History

The harness tracks all invocations for debugging:

Project Structure

Organize your tests to mirror your resource structure:

Sample conftest.py

Running Tests

Run tests with pytest:

What’s Next

Lifecycle Methods

Deep dive into on_create, on_update, and on_delete.

SDK Reference

Full SDK documentation.