@@ -29,7 +29,7 @@ fn test_create_or_open_directory() {
29
29
futures:: executor:: block_on ( test_create_or_open_async_then_delete (
30
30
& db,
31
31
& directory,
32
- vec ! [ String :: from( "application " ) ] ,
32
+ vec ! [ String :: from( "a " ) ] ,
33
33
) )
34
34
. expect ( "failed to run" ) ;
35
35
@@ -43,15 +43,117 @@ fn test_create_or_open_directory() {
43
43
futures:: executor:: block_on ( test_list ( & db, & directory, vec ! [ String :: from( "a" ) ] , 10 ) )
44
44
. expect ( "failed to run" ) ;
45
45
46
- // TODO: fix prefix
47
- // futures::executor::block_on(test_prefix(
48
- // &db,
49
- // vec![String::from("prefix")],
50
- // vec![0x01, 0x02],
51
- // ))
52
- // .expect("failed to run");
46
+ futures:: executor:: block_on ( test_children_content_subspace (
47
+ & db,
48
+ & directory,
49
+ vec ! [ String :: from( "c" ) ] ,
50
+ ) )
51
+ . expect ( "failed to run" ) ;
52
+
53
+ futures:: executor:: block_on ( test_bad_layer ( & db) ) . expect ( "failed to run" ) ;
54
+
55
+ eprintln ! ( "clearing all keys" ) ;
56
+ let trx = db. create_trx ( ) . expect ( "cannot create txn" ) ;
57
+ trx. clear_range ( b"" , b"\xff " ) ;
58
+ futures:: executor:: block_on ( trx. commit ( ) ) . expect ( "could not clear keys" ) ;
59
+
60
+ // test deletions, first we need to create it
61
+ futures:: executor:: block_on ( test_create_or_open_async_then_delete (
62
+ & db,
63
+ & directory,
64
+ vec ! [ String :: from( "deletion" ) ] ,
65
+ ) )
66
+ . expect ( "failed to run" ) ;
67
+
68
+ futures:: executor:: block_on ( test_create_then_delete (
69
+ & db,
70
+ & directory,
71
+ vec ! [ String :: from( "n0" ) ] ,
72
+ 1 ,
73
+ ) )
74
+ . expect ( "failed to run" ) ;
75
+
76
+ futures:: executor:: block_on ( test_prefix (
77
+ & db,
78
+ vec ! [ String :: from( "prefix" ) ] ,
79
+ vec ! [ 0xFC , 0xFC ] ,
80
+ ) )
81
+ . expect ( "failed to run" ) ;
82
+ futures:: executor:: block_on ( test_not_allowed_prefix ( & db, vec ! [ 0xFC , 0xFC ] ) )
83
+ . expect_err ( "should have failed" ) ;
84
+
85
+ // moves
86
+ eprintln ! ( "clearing all keys" ) ;
87
+ let trx = db. create_trx ( ) . expect ( "cannot create txn" ) ;
88
+ trx. clear_range ( b"" , b"\xff " ) ;
89
+ futures:: executor:: block_on ( trx. commit ( ) ) . expect ( "could not clear keys" ) ;
90
+
91
+ futures:: executor:: block_on ( test_create_then_move_to (
92
+ & db,
93
+ & directory,
94
+ vec ! [ String :: from( "d" ) , String :: from( "e" ) ] ,
95
+ vec ! [ String :: from( "a" ) ] ,
96
+ ) )
97
+ . expect ( "failed to run" ) ;
98
+
99
+ // trying to move on empty path
100
+ match futures:: executor:: block_on ( test_move_to (
101
+ & db,
102
+ & directory,
103
+ vec ! [ String :: from( "dsa" ) ] ,
104
+ vec ! [ ] ,
105
+ ) ) {
106
+ Err ( DirectoryError :: NoPathProvided ) => { }
107
+ _ => panic ! ( "should have failed" ) ,
108
+ }
109
+
110
+ // trying to move on empty path
111
+ match futures:: executor:: block_on ( test_move_to (
112
+ & db,
113
+ & directory,
114
+ vec ! [ ] ,
115
+ vec ! [ String :: from( "dsa" ) ] ,
116
+ ) ) {
117
+ Err ( DirectoryError :: NoPathProvided ) => { }
118
+ Err ( err) => panic ! ( "should have NoPathProvided, got {:?}" , err) ,
119
+ Ok ( ( ) ) => panic ! ( "should not be fine" ) ,
120
+ }
121
+
122
+ // source path does not exists
123
+ match futures:: executor:: block_on ( test_move_to (
124
+ & db,
125
+ & directory,
126
+ vec ! [ String :: from( "e" ) ] ,
127
+ vec ! [ String :: from( "f" ) ] ,
128
+ ) ) {
129
+ Err ( DirectoryError :: PathDoesNotExists ) => { }
130
+ Err ( err) => panic ! ( "should have NoPathProvided, got {:?}" , err) ,
131
+ Ok ( ( ) ) => panic ! ( "should not be fine" ) ,
132
+ }
53
133
54
- futures:: executor:: block_on ( test_bad_layer ( & db) ) . expect_err ( "should have failed" ) ;
134
+ // destination's parent does not exists
135
+ match futures:: executor:: block_on ( test_create_then_move_to (
136
+ & db,
137
+ & directory,
138
+ vec ! [ String :: from( "a" ) , String :: from( "g" ) ] ,
139
+ vec ! [ String :: from( "i-do-not-exists-yet" ) , String :: from( "z" ) ] ,
140
+ ) ) {
141
+ Err ( DirectoryError :: ParentDirDoesNotExists ) => { }
142
+ Err ( err) => panic ! ( "should have ParentDirDoesNotExists, got {:?}" , err) ,
143
+ Ok ( ( ) ) => panic ! ( "should not be fine" ) ,
144
+ }
145
+
146
+ // destination not empty
147
+ match futures:: executor:: block_on ( test_create_then_move_to (
148
+ & db,
149
+ & directory,
150
+ vec ! [ String :: from( "a" ) , String :: from( "g" ) ] ,
151
+ vec ! [ String :: from( "a" ) , String :: from( "g" ) ] ,
152
+ ) ) {
153
+ Err ( DirectoryError :: BadDestinationDirectory ) => { }
154
+ Err ( err) => panic ! ( "should have BadDestinationDirectory, got {:?}" , err) ,
155
+ Ok ( ( ) ) => panic ! ( "should not be fine" ) ,
156
+ }
55
157
}
56
158
57
159
async fn test_prefix (
@@ -89,7 +191,7 @@ async fn test_not_allowed_prefix(db: &Database, prefix: Vec<u8>) -> Result<(), D
89
191
directory
90
192
. create_or_open (
91
193
& trx,
92
- vec ! [ String :: from( "bad_layer " ) ] ,
194
+ vec ! [ String :: from( "prefix_not_allowed " ) ] ,
93
195
Some ( prefix. to_owned ( ) ) ,
94
196
None ,
95
197
)
@@ -288,23 +390,27 @@ async fn test_create_or_open_async_then_delete(
288
390
}
289
391
290
392
/// testing that we throwing Err(DirectoryError::IncompatibleLayer)
291
- async fn test_bad_layer ( db : & Database ) -> Result < DirectorySubspace , DirectoryError > {
393
+ async fn test_bad_layer ( db : & Database ) -> Result < ( ) , DirectoryError > {
292
394
let directory = DirectoryLayer {
293
395
..Default :: default ( )
294
396
} ;
295
397
let trx = db. create_trx ( ) ?;
296
398
399
+ eprintln ! ( "creating directory with one layer" ) ;
297
400
directory
298
401
. create_or_open ( & trx, vec ! [ String :: from( "bad_layer" ) ] , None , Some ( vec ! [ 0u8 ] ) )
299
402
. await ?;
300
403
301
- let directory = DirectoryLayer {
302
- ..Default :: default ( )
303
- } ;
404
+ trx. commit ( ) . await . expect ( "cannot commit" ) ;
405
+ let trx = db. create_trx ( ) ?;
304
406
305
- return directory
407
+ eprintln ! ( "opening directory with another" ) ;
408
+ let result = directory
306
409
. create_or_open ( & trx, vec ! [ String :: from( "bad_layer" ) ] , None , Some ( vec ! [ 1u8 ] ) )
307
410
. await ;
411
+
412
+ assert ! ( result. is_err( ) , "expected an error, got {:?}" , result) ;
413
+ Ok ( ( ) )
308
414
}
309
415
310
416
/// testing list functionality. Will open paths and create n sub-folders.
@@ -352,3 +458,35 @@ async fn test_list(
352
458
353
459
Ok ( ( ) )
354
460
}
461
+
462
+ /// checks that the content_subspace of the children is inside the parent
463
+ async fn test_children_content_subspace (
464
+ db : & Database ,
465
+ directory : & DirectoryLayer ,
466
+ paths : Vec < String > ,
467
+ ) -> Result < ( ) , DirectoryError > {
468
+ let trx = db. create_trx ( ) ?;
469
+
470
+ eprintln ! ( "parent = {:?}" , paths. to_owned( ) ) ;
471
+
472
+ let _root_subspace = directory
473
+ . create_or_open ( & trx, paths. to_owned ( ) , None , None )
474
+ . await ?;
475
+
476
+ let mut children_path = paths. clone ( ) ;
477
+ children_path. push ( String :: from ( "nested" ) ) ;
478
+ eprintln ! ( "children = {:?}" , children_path. to_owned( ) ) ;
479
+
480
+ let children_subspace = directory
481
+ . create_or_open ( & trx, children_path. to_owned ( ) , None , None )
482
+ . await ?;
483
+
484
+ trx. commit ( ) . await . expect ( "could not commit" ) ;
485
+ let trx = db. create_trx ( ) ?;
486
+
487
+ let open_children_subspace = directory. open ( & trx, children_path. to_owned ( ) , None ) . await ?;
488
+
489
+ assert_eq ! ( children_subspace. bytes( ) , open_children_subspace. bytes( ) ) ;
490
+
491
+ Ok ( ( ) )
492
+ }
0 commit comments