Skip to content

Running Tests

Test suite and testing practices for bindcar.

Run All Tests

cargo test

Test Types

Unit Tests

Test individual functions and modules:

cargo test --lib

Located in: - src/auth.rs - Authentication tests - src/zones.rs - Zone configuration tests - src/rndc.rs - RNDC executor tests

Integration Tests

Test API endpoints and workflows:

cargo test --test '*'

Located in tests/ directory.

Running Specific Tests

By Name

cargo test test_auth_middleware

By Module

cargo test zones::

With Output

cargo test -- --nocapture

Test Coverage

Currently no coverage tooling configured. Future improvement.

Writing Tests

Unit Test Example

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_zone_config_validation() {
        let config = ZoneConfig {
            ttl: 3600,
            // ...
        };
        assert!(config.is_valid());
    }
}

Integration Test Example

#[tokio::test]
async fn test_create_zone() {
    let app = create_test_app().await;

    let response = app
        .post("/api/v1/zones")
        .json(&zone_request)
        .send()
        .await;

    assert_eq!(response.status(), StatusCode::CREATED);
}

Continuous Integration

Tests run automatically on: - Pull requests - Pushes to main branch

See .github/workflows/pr.yml.

Next Steps