githubEdit

Testing Providers

This guide covers testing strategies for cloud provider implementations.

Testing Levels

flowchart BT
    unit["Unit Tests<br/>(Mocked API responses)<br/>cargo test"]
    integration["Integration Tests<br/>(Real API, real resources)<br/>cargo test --ignored"]

    unit --> integration

Unit Tests with Mocked API

Setup

Add test dependencies to Cargo.toml:

[dev-dependencies]
wiremock = "0.6"
tokio-test = "0.4"
serde_json = "1.0"

Creating a Testable Provider

Add a constructor that accepts a custom base URL:

Test Structure


Testing Each Method

Testing create_instance

Testing destroy_instance

Testing get_instance

Testing wait_ready

Testing list_instances

Testing Authentication Errors


Integration Tests

Integration tests use real API credentials and create real resources.

Setup

Full Lifecycle Test

Running Integration Tests


Test Utilities

Fixtures Module

Create reusable test fixtures:

Test Coverage

Check test coverage:


CI Integration

GitHub Actions


Test Checklist

Before submitting provider tests:

Last updated

Was this helpful?