1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
//! Integration tests for the embedded stores (LMDB, DuckDB, SQLite).
//!
//! These need only the native libraries the crates link against, so
//! unlike the endpoint tests they never skip: a failure here means the
//! store is genuinely unusable.
use std::path::PathBuf;
fn scratch(tag: &str) -> PathBuf {
let mut dir = std::env::temp_dir();
dir.push(format!(
"genenetwork4-embedded-{}-{}",
tag,
std::process::id()
));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).expect("create scratch dir");
dir
}
#[test]
fn lmdb_store_and_read_back() {
let dir = scratch("lmdb");
let got =
genenetwork4::embedded::lmdb_roundtrip(&dir, b"gene", b"Gria1").expect("LMDB round-trip");
assert_eq!(got, b"Gria1");
// The value must survive a fresh environment handle (i.e. it is
// really on disk, not just in the writer's memory).
let again = genenetwork4::embedded::lmdb_roundtrip(&dir, b"gene", b"Gria1")
.expect("LMDB second round-trip");
assert_eq!(again, b"Gria1");
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn duckdb_query_row_count() {
assert_eq!(
genenetwork4::embedded::duckdb_roundtrip().expect("DuckDB query"),
2
);
}
#[test]
fn sqlite_query_row_count() {
let mut db = scratch("sqlite");
db.push("test.db");
assert_eq!(
genenetwork4::embedded::sqlite_roundtrip(&db).expect("SQLite query"),
3
);
let _ = std::fs::remove_file(&db);
}
|