Skip to content

Commit dc9bd2f

Browse files
committed
table_index: reduce some test code duplication
1 parent 005cfe4 commit dc9bd2f

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

  • crates/table/src/table_index

crates/table/src/table_index/mod.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,7 @@ impl TableIndex {
23342334
mod test {
23352335
use super::*;
23362336
use crate::page_pool::PagePool;
2337+
use crate::table::Table;
23372338
use crate::{blob_store::HashMapBlobStore, table::test::table};
23382339
use core::ops::Bound::*;
23392340
use decorum::Total;
@@ -2375,6 +2376,10 @@ mod test {
23752376
}
23762377
}
23772378

2379+
fn setup(ty: ProductType) -> (Table, PagePool, HashMapBlobStore) {
2380+
(table(ty), PagePool::new_for_test(), HashMapBlobStore::default())
2381+
}
2382+
23782383
fn new_index(row_type: &ProductType, cols: &ColList, is_unique: bool, kind: IndexKind) -> TableIndex {
23792384
TableIndex::new(row_type, cols.clone(), kind, is_unique).unwrap()
23802385
}
@@ -2452,9 +2457,7 @@ mod test {
24522457
#[test]
24532458
fn remove_nonexistent_noop((ty, cols, pv) in gen_row_and_cols(), kind: IndexKind, is_unique: bool) {
24542459
let mut index = new_index(&ty, &cols, is_unique, kind);
2455-
let mut table = table(ty);
2456-
let pool = PagePool::new_for_test();
2457-
let mut blob_store = HashMapBlobStore::default();
2460+
let (mut table, pool, mut blob_store) = setup(ty);
24582461
let row_ref = table.insert(&pool, &mut blob_store, &pv).unwrap().1;
24592462
prop_assert_eq!(unsafe { index.delete(row_ref) }, false);
24602463
prop_assert!(index.idx.is_empty());
@@ -2466,9 +2469,7 @@ mod test {
24662469
#[test]
24672470
fn insert_delete_noop((ty, cols, pv) in gen_row_and_cols(), kind: IndexKind, is_unique: bool) {
24682471
let mut index = new_index(&ty, &cols, is_unique, kind);
2469-
let mut table = table(ty);
2470-
let pool = PagePool::new_for_test();
2471-
let mut blob_store = HashMapBlobStore::default();
2472+
let (mut table, pool, mut blob_store) = setup(ty);
24722473
let row_ref = table.insert(&pool, &mut blob_store, &pv).unwrap().1;
24732474
let value = get_fields(&cols, &pv);
24742475

@@ -2499,9 +2500,7 @@ mod test {
24992500
let ty = ProductType::from(ty.into_boxed_slice());
25002501

25012502
let mut index = new_index(&ty, &cols, false, kind);
2502-
let mut table = table(ty);
2503-
let pool = PagePool::new_for_test();
2504-
let mut blob_store = HashMapBlobStore::default();
2503+
let (mut table, pool, mut blob_store) = setup(ty);
25052504

25062505
let num_vals = vals.len();
25072506
for val in vals {
@@ -2522,9 +2521,7 @@ mod test {
25222521
#[test]
25232522
fn insert_again_violates_unique_constraint((ty, cols, pv) in gen_row_and_cols(), kind: IndexKind) {
25242523
let mut index = new_index(&ty, &cols, true, kind);
2525-
let mut table = table(ty);
2526-
let pool = PagePool::new_for_test();
2527-
let mut blob_store = HashMapBlobStore::default();
2524+
let (mut table, pool, mut blob_store) = setup(ty);
25282525
let row_ref = table.insert(&pool, &mut blob_store, &pv).unwrap().1;
25292526
let value = get_fields(&cols, &pv);
25302527

@@ -2561,9 +2558,7 @@ mod test {
25612558
let cols = 0.into();
25622559
let ty = ProductType::from_iter([AlgebraicType::U64]);
25632560
let mut index = new_index(&ty, &cols, is_unique, kind);
2564-
let mut table = table(ty);
2565-
let pool = PagePool::new_for_test();
2566-
let mut blob_store = HashMapBlobStore::default();
2561+
let (mut table, pool, mut blob_store) = setup(ty);
25672562

25682563
let prev = needle - 1;
25692564
let next = needle + 1;
@@ -2662,9 +2657,7 @@ mod test {
26622657
let mut index = new_index(&row_ty, &[0].into(), is_unique, kind);
26632658

26642659
// Construct the table and add `val` as a row.
2665-
let mut table = table(row_ty);
2666-
let pool = PagePool::new_for_test();
2667-
let mut blob_store = HashMapBlobStore::default();
2660+
let (mut table, pool, mut blob_store) = setup(row_ty);
26682661
let pv = product![val.clone()];
26692662
let row_ref = table.insert(&pool, &mut blob_store, &pv).unwrap().1;
26702663

0 commit comments

Comments
 (0)