add tests for backup-before-migrate and position shared prefix
Extra test coverage for db::backup_before_migrate (up-to-date DB
path) and position::between with shared prefix inputs.
diff --git a/src/db.rs b/src/db.rs
index f9dd825..cc47378 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -155,4 +155,24 @@ mod tests {
.collect();
assert_eq!(baks.len(), 1, "should create exactly one backup file");
}
+
+ #[tokio::test]
+ async fn no_backup_when_already_up_to_date() {
+ let dir = tempdir().unwrap();
+ let db_path = dir.path().join("test.db");
+
+ // First connect runs all migrations
+ let pool = connect(&db_path).await.unwrap();
+ pool.close().await;
+
+ // Second connect — all migrations already applied, no backup
+ let _pool2 = connect(&db_path).await.unwrap();
+
+ let baks: Vec<_> = std::fs::read_dir(dir.path())
+ .unwrap()
+ .filter_map(|e| e.ok())
+ .filter(|e| e.path().extension().is_some_and(|ext| ext == "bak"))
+ .collect();
+ assert!(baks.is_empty(), "up-to-date DB should not create a backup");
+ }
}
diff --git a/src/position.rs b/src/position.rs
index eadfc0d..377165b 100644
--- a/src/position.rs
+++ b/src/position.rs
@@ -92,6 +92,13 @@ mod tests {
assert!(*pos < *"z", "expected {pos} < z");
}
+ #[test]
+ fn between_shared_prefix() {
+ let pos = between("ma", "mz");
+ assert!(*pos > *"ma", "expected {pos} > ma");
+ assert!(*pos < *"mz", "expected {pos} < mz");
+ }
+
#[test]
fn between_adjacent() {
let pos = between("a", "b");