githubEdit

Testing Guide

This guide covers testing strategies, tools, and best practices for spuff.

Test Organization

spuff/
├── src/
│   ├── provider/
│   │   └── digitalocean.rs  # Unit tests in #[cfg(test)] mod
│   └── ...
└── tests/
    └── integration/         # Integration tests

Running Tests

All Tests

# Run all unit tests
cargo test --all

# Run with output
cargo test --all -- --nocapture

# Run specific test
cargo test test_name

# Run tests for a specific crate
cargo test -p spuff

Integration Tests

Integration tests require cloud credentials:

Unit Testing

Testing Provider Methods

Use wiremock for API mocking:

Testing SSH Functions

Mock the SSH command:

Testing Cloud-Init Generation

Testing Configuration

Integration Testing

Full Lifecycle Test

SSH Integration Test

Test Utilities

Fixtures

Test Helpers

Mocking

HTTP Mocking with wiremock

Mocking Time

For timeout tests:

Test Coverage

Generate Coverage Report

Coverage Goals

  • Unit tests: 80%+ coverage

  • Critical paths (provider, SSH): 90%+ coverage

  • Integration tests for all happy paths

Best Practices

Test Naming

Test Structure (Arrange-Act-Assert)

Avoiding Flaky Tests

  1. Don't rely on timing

  2. Use deterministic test data

  3. Clean up resources in tests

  4. Isolate tests from each other

Test Documentation

CI Integration

Tests run automatically on PR:

Running Specific Test Categories

Last updated

Was this helpful?