1
1
// Test script to verify OpenDAL storage configuration
2
2
use std:: path:: Path ;
3
3
4
- fn main ( ) {
5
- println ! ( "Testing OpenDAL storage configuration..." ) ;
6
-
4
+ #[ test]
5
+ fn test_storage_config_default ( ) {
7
6
// Test default configuration
8
7
let default_config = atomic_lib:: StorageConfig :: default ( ) ;
9
- println ! ( "Default config: {:?}" , default_config) ;
10
8
assert_eq ! ( default_config. enabled_backends, vec![ "sled" . to_string( ) , "dashmap" . to_string( ) ] ) ;
11
9
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 ( ) {
13
17
// Test custom configuration
14
18
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( ) ] ,
16
20
prefer_memory : true ,
17
21
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 ,
18
44
redb_path : None ,
19
45
fs_path : None ,
20
46
} ;
21
- println ! ( "Custom config: {:?}" , custom_config) ;
22
47
23
- // Test DB initialization with config
24
- let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
25
48
let result = atomic_lib:: Db :: init_with_config (
26
- temp_dir . path ( ) ,
49
+ Path :: new ( & tmp_dir_path ) ,
27
50
"http://localhost" . to_string ( ) ,
28
51
custom_config,
29
52
) ;
30
53
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( ) ) ;
35
82
36
- println ! ( "All tests passed!" ) ;
83
+ // Clean up
84
+ let _cleanup = std:: fs:: remove_dir_all ( & tmp_dir_path) ;
37
85
}
0 commit comments