dynoxide-rs 0.11.1

A lightweight, embeddable DynamoDB emulator backed by SQLite
Documentation
//! Tests that verify database compatibility between Option A (SQLCipher always linked)
//! and Option B (plain SQLite default, SQLCipher behind feature flag).
//!
//! These tests run under default features (plain SQLite) and read fixtures
//! that were created by the SQLCipher-linked build.

use dynoxide::Database;

const FIXTURE_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures");

#[test]
fn option_a_unencrypted_db_readable_by_plain_sqlite() {
    // Open a throwaway copy: Database::new runs schema migrations, which would
    // otherwise mutate the committed fixture in place on every test run.
    let tmp = tempfile::tempdir().unwrap();
    let path = tmp.path().join("option-a-unencrypted.db");
    std::fs::copy(format!("{FIXTURE_DIR}/option-a-unencrypted.db"), &path).unwrap();
    let db = Database::new(path.to_str().unwrap())
        .expect("Should open Option A unencrypted DB with plain SQLite");

    // Verify the data written by the SQLCipher-linked build is readable
    let key = dynoxide::item! { "pk" => "user#1" };
    let resp = db
        .get_item(dynoxide::actions::get_item::GetItemRequest {
            table_name: "Users".to_string(),
            key,
            ..Default::default()
        })
        .expect("GetItem should succeed");

    let item = resp.item.expect("Item should exist");
    assert_eq!(
        item.get("name").unwrap(),
        &dynoxide::AttributeValue::S("Alice".to_string()),
    );
}

#[test]
fn option_a_encrypted_db_gives_clear_error() {
    let path = format!("{FIXTURE_DIR}/option-a-encrypted.db");
    let result = Database::new(&path);

    match result {
        Ok(_) => panic!("Opening encrypted DB without key should fail"),
        Err(err) => {
            let msg = err.to_string();
            assert!(
                msg.contains("encrypted") || msg.contains("not a valid"),
                "Error should mention encryption, got: {msg}"
            );
        }
    }
}