Skip to content

Commit e6bf248

Browse files
committed
Long term dream #433 continuation of pull request #644
1 parent 6e76292 commit e6bf248

File tree

1 file changed

+63
-15
lines changed

1 file changed

+63
-15
lines changed
Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,85 @@
11
// Test script to verify OpenDAL storage configuration
22
use std::path::Path;
33

4-
fn main() {
5-
println!("Testing OpenDAL storage configuration...");
6-
4+
#[test]
5+
fn test_storage_config_default() {
76
// Test default configuration
87
let default_config = atomic_lib::StorageConfig::default();
9-
println!("Default config: {:?}", default_config);
108
assert_eq!(default_config.enabled_backends, vec!["sled".to_string(), "dashmap".to_string()]);
119
assert_eq!(default_config.prefer_memory, false);
12-
10+
assert!(default_config.rocksdb_path.is_none());
11+
assert!(default_config.redb_path.is_none());
12+
assert!(default_config.fs_path.is_none());
13+
}
14+
15+
#[test]
16+
fn test_storage_config_custom() {
1317
// Test custom configuration
1418
let custom_config = atomic_lib::StorageConfig {
15-
enabled_backends: vec!["dashmap".to_string(), "rocksdb".to_string()],
19+
enabled_backends: vec!["dashmap".to_string(), "sled".to_string()],
1620
prefer_memory: true,
1721
rocksdb_path: Some(Path::new("/tmp/rocksdb").to_path_buf()),
22+
redb_path: Some(Path::new("/tmp/redb").to_path_buf()),
23+
fs_path: Some(Path::new("/tmp/fs").to_path_buf()),
24+
};
25+
26+
assert_eq!(custom_config.enabled_backends, vec!["dashmap".to_string(), "sled".to_string()]);
27+
assert!(custom_config.prefer_memory);
28+
assert_eq!(custom_config.rocksdb_path, Some(Path::new("/tmp/rocksdb").to_path_buf()));
29+
assert_eq!(custom_config.redb_path, Some(Path::new("/tmp/redb").to_path_buf()));
30+
assert_eq!(custom_config.fs_path, Some(Path::new("/tmp/fs").to_path_buf()));
31+
}
32+
33+
#[test]
34+
fn test_db_init_with_custom_config() {
35+
// Test DB initialization with custom config
36+
let tmp_dir_path = ".temp/db/test_storage_config";
37+
let _try_remove_existing = std::fs::remove_dir_all(&tmp_dir_path);
38+
std::fs::create_dir_all(&tmp_dir_path).unwrap();
39+
40+
let custom_config = atomic_lib::StorageConfig {
41+
enabled_backends: vec!["sled".to_string(), "dashmap".to_string()],
42+
prefer_memory: false,
43+
rocksdb_path: None,
1844
redb_path: None,
1945
fs_path: None,
2046
};
21-
println!("Custom config: {:?}", custom_config);
2247

23-
// Test DB initialization with config
24-
let temp_dir = tempfile::tempdir().unwrap();
2548
let result = atomic_lib::Db::init_with_config(
26-
temp_dir.path(),
49+
Path::new(&tmp_dir_path),
2750
"http://localhost".to_string(),
2851
custom_config,
2952
);
3053

31-
match result {
32-
Ok(_) => println!("✓ DB initialized successfully with custom config"),
33-
Err(e) => println!("✗ Failed to initialize DB: {}", e),
34-
}
54+
assert!(result.is_ok(), "Failed to initialize DB with custom config: {:?}", result.err());
55+
56+
// Clean up
57+
let _cleanup = std::fs::remove_dir_all(&tmp_dir_path);
58+
}
59+
60+
#[test]
61+
fn test_db_init_with_prefer_memory() {
62+
// Test DB initialization with prefer_memory option
63+
let tmp_dir_path = ".temp/db/test_storage_prefer_memory";
64+
let _try_remove_existing = std::fs::remove_dir_all(&tmp_dir_path);
65+
std::fs::create_dir_all(&tmp_dir_path).unwrap();
66+
67+
let memory_config = atomic_lib::StorageConfig {
68+
enabled_backends: vec!["dashmap".to_string(), "sled".to_string()],
69+
prefer_memory: true,
70+
rocksdb_path: None,
71+
redb_path: None,
72+
fs_path: None,
73+
};
74+
75+
let result = atomic_lib::Db::init_with_config(
76+
Path::new(&tmp_dir_path),
77+
"http://localhost".to_string(),
78+
memory_config,
79+
);
80+
81+
assert!(result.is_ok(), "Failed to initialize DB with prefer_memory config: {:?}", result.err());
3582

36-
println!("All tests passed!");
83+
// Clean up
84+
let _cleanup = std::fs::remove_dir_all(&tmp_dir_path);
3785
}

0 commit comments

Comments
 (0)