@@ -29,7 +29,7 @@ fn test_create_or_open_directory() {
2929 futures:: executor:: block_on ( test_create_or_open_async_then_delete (
3030 & db,
3131 & directory,
32- vec ! [ String :: from( "application " ) ] ,
32+ vec ! [ String :: from( "a " ) ] ,
3333 ) )
3434 . expect ( "failed to run" ) ;
3535
@@ -43,15 +43,117 @@ fn test_create_or_open_directory() {
4343 futures:: executor:: block_on ( test_list ( & db, & directory, vec ! [ String :: from( "a" ) ] , 10 ) )
4444 . expect ( "failed to run" ) ;
4545
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+ }
53133
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+ }
55157}
56158
57159async fn test_prefix (
@@ -89,7 +191,7 @@ async fn test_not_allowed_prefix(db: &Database, prefix: Vec<u8>) -> Result<(), D
89191 directory
90192 . create_or_open (
91193 & trx,
92- vec ! [ String :: from( "bad_layer " ) ] ,
194+ vec ! [ String :: from( "prefix_not_allowed " ) ] ,
93195 Some ( prefix. to_owned ( ) ) ,
94196 None ,
95197 )
@@ -288,23 +390,27 @@ async fn test_create_or_open_async_then_delete(
288390}
289391
290392/// 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 > {
292394 let directory = DirectoryLayer {
293395 ..Default :: default ( )
294396 } ;
295397 let trx = db. create_trx ( ) ?;
296398
399+ eprintln ! ( "creating directory with one layer" ) ;
297400 directory
298401 . create_or_open ( & trx, vec ! [ String :: from( "bad_layer" ) ] , None , Some ( vec ! [ 0u8 ] ) )
299402 . await ?;
300403
301- let directory = DirectoryLayer {
302- ..Default :: default ( )
303- } ;
404+ trx. commit ( ) . await . expect ( "cannot commit" ) ;
405+ let trx = db. create_trx ( ) ?;
304406
305- return directory
407+ eprintln ! ( "opening directory with another" ) ;
408+ let result = directory
306409 . create_or_open ( & trx, vec ! [ String :: from( "bad_layer" ) ] , None , Some ( vec ! [ 1u8 ] ) )
307410 . await ;
411+
412+ assert ! ( result. is_err( ) , "expected an error, got {:?}" , result) ;
413+ Ok ( ( ) )
308414}
309415
310416/// testing list functionality. Will open paths and create n sub-folders.
@@ -352,3 +458,35 @@ async fn test_list(
352458
353459 Ok ( ( ) )
354460}
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