use tempfile::TempDir;
pub fn create_test_db() -> TempDir {
create_test_db_with_compression(false)
}
pub fn create_test_db_with_compression(compression: bool) -> TempDir {
let temp_dir = tempfile::tempdir().expect("Failed to create temp directory");
{
let db = sled::Config::new()
.use_compression(compression)
.path(temp_dir.path())
.open()
.expect("Failed to create test database");
db.insert(b"user_001", b"John Doe").unwrap();
db.insert(b"user_002", b"Jane Smith").unwrap();
db.insert(b"user_003", b"Bob Johnson").unwrap();
db.insert(b"config_theme", b"dark").unwrap();
db.insert(b"config_language", b"en-US").unwrap();
db.insert(b"session_abc123", b"2024-01-01T10:00:00Z")
.unwrap();
db.insert(b"session_def456", b"2024-01-01T11:00:00Z")
.unwrap();
db.insert(b"email_john", b"john@example.com").unwrap();
db.insert(b"email_jane", b"jane@example.com").unwrap();
db.insert(b"data_binary", &[0u8, 1, 2, 3, 255]).unwrap();
db.flush().unwrap();
}
temp_dir
}
pub fn create_empty_test_db() -> TempDir {
let temp_dir = tempfile::tempdir().expect("Failed to create temp directory");
{
let db = sled::open(temp_dir.path()).expect("Failed to create test database");
db.flush().unwrap();
} temp_dir
}