#[cfg(test)]
mod tests {
    use crate::rocks_engine::RocksEngine;
    use crate::StorageEngine; // Import trait
    use std::sync::Arc;
    use tempfile::TempDir;

    fn create_test_db() -> (Arc<RocksEngine>, TempDir) {
        let temp_dir = TempDir::new().unwrap();
        let engine = Arc::new(RocksEngine::new(temp_dir.path().to_str().unwrap()).unwrap());
        (engine, temp_dir)
    }

    #[tokio::test]
    async fn test_raw_put_get() {
        let (engine, _dir) = create_test_db();

        let key = b"k1";
        let val = b"v1";

        engine.put_raw(key, val).await.unwrap();
        let res = engine.get_raw(key).await.unwrap();
        assert_eq!(res, Some(val.to_vec()));
    }

    #[tokio::test]
    async fn test_cas_success() {
        let (engine, _dir) = create_test_db();

        let key = b"cas_key";
        let val = b"v1";

        // Create (expected 0)
        let res = engine.compare_and_swap(key, 0, val).await.unwrap();
        assert!(res.success);
        assert_eq!(res.new_version, 1); // Assuming starts at 1
        let entry = engine.get_cas(key).await.unwrap().unwrap();
        assert_eq!(entry.0, 1);
        assert_eq!(entry.1, val.to_vec());

        // Update (expected 1)
        let val2 = b"v2";
        let res2 = engine.compare_and_swap(key, 1, val2).await.unwrap();
        assert!(res2.success);
        assert_eq!(res2.new_version, 2);
        let entry2 = engine.get_cas(key).await.unwrap().unwrap();
        assert_eq!(entry2.0, 2);
        assert_eq!(entry2.1, val2.to_vec());
    }

    #[tokio::test]
    async fn test_cas_conflict() {
        let (engine, _dir) = create_test_db();

        let key = b"cas_conflict";
        let val = b"v1";

        // Create
        engine.compare_and_swap(key, 0, val).await.unwrap();

        // Conflict (expected 0, but is 1)
        let res = engine.compare_and_swap(key, 0, val).await.unwrap();
        assert!(!res.success);
        assert_eq!(res.current_version, 1);
    }
}
