diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-01-14 12:46:19 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-01-14 12:46:19 +0200 |
| commit | 14b77c5cdfdcb1112deeacba010879037b456020 (patch) | |
| tree | 6ddff5838ce29087b98960e5e6b62cce0690596c | |
| parent | 63424ee9327552dd4119e9e63cfece56eb2743b9 (diff) | |
Test batch_find_by
| -rw-r--r-- | log_db/tests/integration.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/log_db/tests/integration.rs b/log_db/tests/integration.rs index 2ef04d1..50f4544 100644 --- a/log_db/tests/integration.rs +++ b/log_db/tests/integration.rs @@ -617,3 +617,36 @@ fn test_range_by_id() { assert_eq!(received_ids, vec![3, 4, 5, 6, 7, 8, 9]); } + +#[test] +fn test_batch_find_by() { + let data_dir = tmp_dir(); + let mut db = DB::<Inst>::configure() + .data_dir(&data_dir) + .initialize() + .expect("Failed to initialize DB instance"); + + let inserted_ids = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + + for id in inserted_ids.iter() { + db.upsert(Inst { + id: *id, + name: Some("Foobar".to_string()), + data: vec![], + }) + .unwrap(); + } + + let batch: Vec<Value> = (2..5).map(Value::Int).collect(); + let result = db.batch_find_by(&Field::Id, &batch).unwrap(); + + assert_eq!(result.len(), batch.len()); + assert_eq!( + result.iter().map(|(tag, _)| *tag).collect::<Vec<usize>>(), + vec![0, 1, 2] + ); + assert_eq!( + result.iter().map(|(_, inst)| inst.id).collect::<Vec<i64>>(), + vec![2, 3, 4] + ); +} |
