From 6254246541c593c347dfd23286324e458b323e59 Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Sun, 25 May 2025 10:25:52 +0300 Subject: [PATCH] use tempfile in test --- Cargo.lock | 5 +++-- bindings/rust/Cargo.toml | 1 + bindings/rust/src/lib.rs | 19 +++++-------------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 849b15a0b..9aad80c35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1721,6 +1721,7 @@ name = "limbo" version = "0.0.20" dependencies = [ "limbo_core", + "tempfile", "thiserror 2.0.12", "tokio", ] @@ -3479,9 +3480,9 @@ checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" [[package]] name = "tempfile" -version = "3.19.1" +version = "3.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7437ac7763b9b123ccf33c338a5cc1bac6f69b45a136c19bdd8a65e3916435bf" +checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" dependencies = [ "fastrand", "getrandom 0.3.2", diff --git a/bindings/rust/Cargo.toml b/bindings/rust/Cargo.toml index c8a3da674..7a4d613e9 100644 --- a/bindings/rust/Cargo.toml +++ b/bindings/rust/Cargo.toml @@ -14,4 +14,5 @@ limbo_core = { workspace = true, features = ["io_uring"] } thiserror = "2.0.9" [dev-dependencies] +tempfile = "3.20.0" tokio = { version = "1.29.1", features = ["full"] } diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index 423432ef2..30816e376 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -352,13 +352,12 @@ impl<'a> FromIterator<&'a limbo_core::Value> for Row { #[cfg(test)] mod tests { use super::*; + use tempfile::NamedTempFile; #[tokio::test] async fn test_database_persistence() -> Result<()> { - let db_path = "test_persistence.db"; - // Ensure a clean state by removing the database file if it exists from a previous run - let _ = std::fs::remove_file(db_path); - let _ = std::fs::remove_file(format!("{}-wal", db_path)); + let temp_file = NamedTempFile::new().unwrap(); + let db_path = temp_file.path().to_str().unwrap(); // First, create the database, a table, and insert some data { @@ -391,18 +390,13 @@ mod tests { assert!(rows.next().await?.is_none(), "Expected no more rows"); - // Clean up the database file - let _ = std::fs::remove_file(db_path); - let _ = std::fs::remove_file(format!("{}-wal", db_path)); Ok(()) } #[tokio::test] async fn test_database_persistence_many_frames() -> Result<()> { - let db_path = "test_persistence_many_frames.db"; - // Ensure a clean state by removing the database file if it exists from a previous run - let _ = std::fs::remove_file(db_path); - let _ = std::fs::remove_file(format!("{}-wal", db_path)); + let temp_file = NamedTempFile::new().unwrap(); + let db_path = temp_file.path().to_str().unwrap(); const NUM_INSERTS: usize = 100; const TARGET_STRING_LEN: usize = 1024; // 1KB @@ -489,9 +483,6 @@ mod tests { ), } - // Clean up the database file - let _ = std::fs::remove_file(db_path); - let _ = std::fs::remove_file(format!("{}-wal", db_path)); Ok(()) } }