Skip to content

Commit

Permalink
use test_db_prefix_scan for all 4 database types
Browse files Browse the repository at this point in the history
  • Loading branch information
antonilol committed Sep 11, 2024
1 parent 8cfdae1 commit dcdc18b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 21 deletions.
10 changes: 10 additions & 0 deletions src/db/lmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,13 @@ impl DBStore {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::DBStore;

#[test]
fn test_db_prefix_scan() {
super::super::test_db_prefix_scan::<DBStore>();
}
}
25 changes: 25 additions & 0 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,28 @@ pub(crate) fn hash_prefix_range(prefix: HashPrefix) -> impl RangeBounds<Serializ

lower..=upper
}

#[cfg(test)]
pub(crate) fn test_db_prefix_scan<D: Database>() {
let dir = tempfile::tempdir().unwrap();
let store = D::open(dir.path(), None, true).unwrap();

let items = [
*b"ab ",
*b"abcdefgh ",
*b"abcdefghj ",
*b"abcdefghjk ",
*b"abcdefghxyz ",
*b"abcdefgi ",
*b"b ",
*b"c ",
];

store.write(&WriteBatch {
txid_rows: items.to_vec(),
..Default::default()
});

let rows = store.iter_txid(*b"abcdefgh");
assert_eq!(rows.collect::<Vec<_>>(), items[1..5]);
}
10 changes: 10 additions & 0 deletions src/db/redb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,13 @@ impl DBStore {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::DBStore;

#[test]
fn test_db_prefix_scan() {
super::super::test_db_prefix_scan::<DBStore>();
}
}
22 changes: 1 addition & 21 deletions src/db/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,27 +502,7 @@ mod tests {

#[test]
fn test_db_prefix_scan() {
let dir = tempfile::tempdir().unwrap();
let store = DBStore::open(dir.path(), None, true).unwrap();

let items = [
*b"ab ",
*b"abcdefgh ",
*b"abcdefghj ",
*b"abcdefghjk ",
*b"abcdefghxyz ",
*b"abcdefgi ",
*b"b ",
*b"c ",
];

store.write(&WriteBatch {
txid_rows: items.to_vec(),
..Default::default()
});

let rows = store.iter_txid(*b"abcdefgh");
assert_eq!(rows.collect::<Vec<_>>(), items[1..5]);
super::super::test_db_prefix_scan::<DBStore>();
}

#[test]
Expand Down
10 changes: 10 additions & 0 deletions src/db/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,13 @@ impl DBStore {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::DBStore;

#[test]
fn test_db_prefix_scan() {
super::super::test_db_prefix_scan::<DBStore>();
}
}

0 comments on commit dcdc18b

Please sign in to comment.