Running Tests
Relevant source files
The following files were used as context for generating this wiki page:
The Sentinel project employs a comprehensive testing strategy to ensure code quality, correctness, and performance. The testing framework is built around standard Rust tooling, augmented with specialized crates for benchmarking, property-based testing, and code coverage analysis. The approach covers everything from basic unit tests for individual functions to more complex integration tests for features like document creation and retrieval.
The testing philosophy is detailed in the Implementation Plan, which outlines a phased approach to building out the test suite in parallel with feature development. This ensures that core functionalities are validated early and that durability, concurrency, and performance are rigorously tested as the system evolves.
Test Suite Structure
Tests in the Sentinel project are organized directly within the source code using conditional compilation attributes (#[cfg(test)]). This co-location of tests and implementation allows for easy access to private functions and modules while keeping the test code separate from the production build.
The IMPLEMENTATION_PLAN.md outlines tests for each development phase, starting with basic file operations and progressing to transactions, caching, and encryption.
Sources: crates/sentinel/src/lib.rs:4-11, IMPLEMENTATION_PLAN.md:300-315
Unit Tests
Unit tests focus on small, isolated pieces of functionality. A simple example is found in the main library file, which verifies the add function.
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
Sources: crates/sentinel/src/lib.rs:4-11
Feature & Integration Tests
As features are developed, they are accompanied by integration-style tests that verify the interaction between different components. The implementation plan provides an example of a test for inserting and retrieving a document, which validates the Store and Collection managers.
The following diagram illustrates the sequence of operations in the planned test_insert_and_retrieve test.
This diagram shows the interaction between the test function, store, collection, and filesystem for a basic insert-and-get operation.
Sources: IMPLEMENTATION_PLAN.md:306-315
#[cfg(test)]
mod tests {
#[tokio::test]
async fn test_insert_and_retrieve() {
let store = Store::new("/tmp/test").unwrap();
let users = store.collection("users").unwrap();
let doc = json!({ "name": "Alice", "email": "alice@example.com" });
users.insert("user-123", doc.clone()).await.unwrap();
let retrieved = users.get("user-123").await.unwrap();
assert_eq!(retrieved.data, doc);
}
}
Sources: IMPLEMENTATION_PLAN.md:306-315
Testing Tools and Dependencies
The project leverages a suite of development dependencies to facilitate robust testing. These are defined in the workspace Cargo.toml and are not included in the final release binary.
Sources: Cargo.toml:343-349, IMPLEMENTATION_PLAN.md:652-663
Core Testing Dependencies
The following table summarizes the key development dependencies used for testing.
| Crate | Version | Purpose |
|---|---|---|
criterion | 0.5 | Benchmarking framework. |
proptest | 1.4 | Property-based testing. |
quickcheck | 1.0 | Randomized testing. |
mockall | 0.12 | Mocking library for creating test doubles. |
tempdir | 0.3 | Creating temporary directories for tests. |
Sources: Cargo.toml:343-349, IMPLEMENTATION_PLAN.md:652-658
Infrastructure Tools
Beyond crate dependencies, the project's testing and quality assurance process relies on several command-line tools.
| Tool | Purpose |
|---|---|
cargo-tarpaulin | Code coverage reporting. |
tokio-console | Asynchronous debugging. |
cargo-flamegraph | Performance profiling. |
cargo-audit | Auditing dependencies for security vulnerabilities. |
clippy | Code linting and style checks. |
rustfmt | Automated code formatting. |
Sources: IMPLEMENTATION_PLAN.md:666-676, Cargo.toml:18-341, rustfmt.toml
Test Execution Flow
While the project is in its early stages, the standard Rust workflow for building and testing applies. The intended development and testing cycle can be inferred from the configured tooling.
This diagram outlines the typical developer workflow for ensuring code quality before committing changes.
Sources: README.md:90-93, IMPLEMENTATION_PLAN.md:666-676, Cargo.toml:18-341
To run the test suite, use the standard Cargo command in the repository root:
cargo test
This command will discover and execute all tests, including unit tests inside library crates and any integration tests.
Sources: crates/sentinel/src/lib.rs:4-11