tank-tests

Crates.iotank-tests
lib.rstank-tests
version0.16.0
created_at2025-09-28 14:58:58.023991+00
updated_at2026-01-20 23:41:42.926545+00
descriptionTest suide for drivers of Tank: the Rust data layer. This is intended to be used by drivers to implement common unit tests.
homepage
repositoryhttps://github.com/TankHQ/tank
max_upload_size
id1858408
size251,360
BarsDev (barsdeveloper)

documentation

README

Tank: Table Abstraction & Navigation Kit logo featuring a green tank with a gear background and stacked database cylinders

tank-tests

Reusable integration test suite for the for Tank: the Rust data layer. Instead of duplicating many nearly identical tests inside every driver crate, tank-tests centralizes them with feature flags so each driver can opt out gracefully skipping unsupported features.

Purpose

  • Ensures consistency: all drivers pass the same baseline CRUD, query, join, multi‑statement and type coverage.
  • Reduces maintenance: add a new scenario once, every driver benefits.
  • Accelerates new driver development: run the suite early, disable what you have not implemented yet, iterate.

Each module focuses on a distinct aspect of Tank functionality. They are orchestrated by execute_tests in src/lib.rs.

Feature Flags

The crate exposes opt-out feature flags ("disable-*") that skip entire capability families when a driver cannot yet support them.

Flag Skips tests that use
disable-arrays Fixed-size arrays
disable-intervals Interval an advanced duration handling
disable-large-integers i128 and u128 columns
disable-lists List/array-like dynamic collection types
disable-maps Map containers
disable-ordering Explicit result ordering
disable-references Referential integrity
disable-transactions Transaction begin/commit/rollback coverage

Use them from the driver crate's Cargo.toml:

[dev-dependencies]
tank-tests = { version = "1", features = ["disable-arrays", "disable-lists", "disable-maps"] }

Setup

  1. Add as a dev-dependency and invoke execute_tests in a tokio::test.
  2. Call init_logs() to get structured output.
  3. Wrap with a mutex to ensure effects do not overlap if the same test is executed twice against the same db.
#[cfg(test)]
mod tests {
    use std::sync::Mutex;
    use tank_core::Driver;
    use tank_mydb::{MyDBConnection, MyDBDriver};
    use tank_tests::{execute_tests, init_logs};
    static MUTEX: Mutex<()> = Mutex::new(());
    #[tokio::test]
    async fn mydb() {
        init_logs();
        let _guard = MUTEX.lock().unwrap();
        let driver = MyDBDriver::new();
        let connection = driver.connect("mydb://localhost:5555".into())
            .await
            .expect("Could not connect to MyDB");
        execute_tests(connection).await; // Runs all enabled modules sequentially
    }
}

Logging control

  • init_logs() sets a test-friendly format and default WARN level (override via RUST_LOG).
  • silent_logs! { ... } macro temporarily mutes logging for false positive error logs when they are expected.
Commit count: 401

cargo fmt