Integration Tests
This directory contains integration tests for RubHub.
Structure
tests/
├── common/
│ └── mod.rs # Shared test utilities
├── integration_tests.rs # Basic workflow tests
├── project_tests.rs # Project-related tests
└── README.md # This file
Shared Utilities (tests/common/mod.rs)
with_backend(test_fn)
Runs a test with a temporary RubHub backend instance.
- Creates isolated temporary directory
- Binds to OS-assigned ports (enables parallel tests)
- Passes
GlobalStateto your test function - Automatically cleans up after test
Example:
with_backend(|state| async move {
let base_url = &state.config.base_url;
let client = test_client();
// Your test code here
}).await;
test_client()
Creates a reqwest HTTP client with cookie store enabled.
Example:
let client = test_client();
let response = client.get(format!("{base_url}/")).send().await?;
response_contains(client, url, needle)
Helper to assert that an HTTP response contains specific text.
Example:
response_contains(&client, &format!("{base_url}/"), "RubHub")
.await
.unwrap();
Adding New Tests
Create a new test file:
- Create
tests/my_tests.rs - Import the common module:
mod common; - Import utilities:
use common::{with_backend, test_client, response_contains}; - Write your tests
Example (tests/my_tests.rs):
mod common;
use common::{test_client, with_backend, response_contains};
#[tokio::test(flavor = "current_thread")]
async fn my_test() {
with_backend(|state| async move {
let base_url = &state.config.base_url;
let client = test_client();
// Test code here
response_contains(&client, &format!("{base_url}/"), "text")
.await
.unwrap();
})
.await;
}
Running Tests
# Run all tests
cargo test
# Run specific test file
cargo test --test integration_tests
# Run specific test
cargo test basic_workflow
# Run with parallel execution (default)
cargo test -- --test-threads=4
# Run with output
cargo test -- --nocapture
Test Features
- ✅ Parallel execution: Tests use OS-assigned ports (no conflicts)
- ✅ Isolated environments: Each test gets its own temp directory
- ✅ Full state access: Tests receive
GlobalStatewith all config - ✅ Cookie-aware: HTTP client maintains sessions automatically
- ✅ Fast cleanup: Temporary directories are removed after tests
Available via GlobalState
Your test functions receive a GlobalState with access to:
state.config.base_url // HTTP server URL (e.g., "http://127.0.0.1:45678")
state.config.ssh_public_host // SSH server host:port
state.config.git_root // Path to git repositories
state.config.dir_root // Test data root directory
// ... and all other config fields
Tips
- Use
#[tokio::test(flavor = "current_thread")]- Matches production runtime - Enable cookie store - The
test_client()helper does this automatically - Use format strings - Build URLs dynamically:
format!("{base_url}/path") - Check the output - Use
--nocaptureto see println! statements - Parallel-safe - All tests can run simultaneously without conflicts