Skip to content

Commit a6a4515

Browse files
0xrinegadeclaude
andcommitted
test(snapshot_db): Use temp directories for isolated test execution
- Add setup_test_db() helper with TempDir - Tests no longer write to default paths - Proper cleanup after tests 🤖 Generated with [Claude Code](https://claude.ai/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 213f743 commit a6a4515

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/utils/snapshot_db.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,18 @@ impl DatabaseStats {
434434
#[cfg(test)]
435435
mod tests {
436436
use super::*;
437+
use tempfile::TempDir;
438+
439+
fn setup_test_db() -> (SnapshotDB, TempDir) {
440+
let tmp_dir = TempDir::new().expect("Failed to create temp dir");
441+
let db_path = tmp_dir.path().join("test.rocksdb");
442+
let db = SnapshotDB::open_path(&db_path).expect("Failed to open test db");
443+
(db, tmp_dir)
444+
}
437445

438446
#[test]
439447
fn test_account_storage() {
440-
let db = SnapshotDB::open().unwrap();
448+
let (db, _tmp_dir) = setup_test_db();
441449

442450
let account = AccountRecord {
443451
address: "TestAccount123".to_string(),
@@ -458,7 +466,7 @@ mod tests {
458466

459467
#[test]
460468
fn test_batch_insert() {
461-
let db = SnapshotDB::open().unwrap();
469+
let (db, _tmp_dir) = setup_test_db();
462470

463471
let accounts = vec![
464472
AccountRecord {

0 commit comments

Comments
 (0)