Rewrite test to use temp dir

This commit is contained in:
김선우
2024-09-15 17:31:55 +09:00
parent 07c4ca9edd
commit ff1c38e0bb
3 changed files with 5 additions and 7 deletions

1
Cargo.lock generated
View File

@@ -400,6 +400,7 @@ dependencies = [
"rstest",
"rusqlite",
"rustyline",
"tempfile",
]
[[package]]

View File

@@ -20,6 +20,7 @@ env_logger = "0.10.1"
limbo_core = { path = "../core" }
rustyline = "12.0.0"
rusqlite = "0.29.0"
tempfile = "3.0.7"
[dev-dependencies]
rstest = "0.18.2"

View File

@@ -1,8 +1,7 @@
use limbo_core::Database;
use std::env;
use std::fs;
use std::path::PathBuf;
use std::sync::Arc;
use tempfile::TempDir;
#[allow(dead_code)]
struct TempDatabase {
@@ -13,12 +12,9 @@ struct TempDatabase {
#[allow(dead_code, clippy::arc_with_non_send_sync)]
impl TempDatabase {
pub fn new(table_sql: &str) -> Self {
let mut path = env::current_dir().unwrap();
let mut path = TempDir::new().unwrap().into_path();
path.push("test.db");
{
if path.exists() {
fs::remove_file(&path).unwrap();
}
let connection = rusqlite::Connection::open(&path).unwrap();
connection.execute(table_sql, ()).unwrap();
}
@@ -47,7 +43,7 @@ mod tests {
let conn = tmp_db.connect_limbo();
let list_query = "SELECT * FROM test";
let max_iterations = 10000;
let max_iterations = 1000;
for i in 0..max_iterations {
if (i % 100) == 0 {
let progress = (i as f64 / max_iterations as f64) * 100.0;