@@ -18,7 +18,7 @@ fn test_directory() {
18
18
19
19
eprintln ! ( "clearing all keys" ) ;
20
20
let trx = db. create_trx ( ) . expect ( "cannot create txn" ) ;
21
- trx. clear_range ( b"\x00 " , b"\xff " ) ;
21
+ trx. clear_range ( b"" , b"\xff " ) ;
22
22
futures:: executor:: block_on ( trx. commit ( ) ) . expect ( "could not clear keys" ) ;
23
23
24
24
eprintln ! ( "creating directories" ) ;
@@ -50,21 +50,97 @@ fn test_directory() {
50
50
51
51
futures:: executor:: block_on ( test_bad_layer ( & db) ) . expect ( "failed to run" ) ;
52
52
53
- futures:: executor:: block_on ( test_move_to (
53
+ futures:: executor:: block_on ( test_create_then_move_to (
54
54
& db,
55
55
& directory,
56
56
vec ! [ String :: from( "d" ) , String :: from( "e" ) ] ,
57
57
vec ! [ String :: from( "a" ) , String :: from( "g" ) ] ,
58
58
) )
59
59
. expect ( "failed to run" ) ;
60
+
61
+ // trying to move on empty path
62
+ match futures:: executor:: block_on ( test_move_to (
63
+ & db,
64
+ & directory,
65
+ vec ! [ String :: from( "dsa" ) ] ,
66
+ vec ! [ ] ,
67
+ ) ) {
68
+ Err ( DirectoryError :: NoPathProvided ) => { }
69
+ _ => panic ! ( "should have failed" ) ,
70
+ }
71
+
72
+ // trying to move on empty path
73
+ match futures:: executor:: block_on ( test_move_to (
74
+ & db,
75
+ & directory,
76
+ vec ! [ ] ,
77
+ vec ! [ String :: from( "dsa" ) ] ,
78
+ ) ) {
79
+ Err ( DirectoryError :: NoPathProvided ) => { }
80
+ Err ( err) => panic ! ( "should have NoPathProvided, got {:?}" , err) ,
81
+ Ok ( ( ) ) => panic ! ( "should not be fine" ) ,
82
+ }
83
+
84
+ // source path does not exists
85
+ match futures:: executor:: block_on ( test_move_to (
86
+ & db,
87
+ & directory,
88
+ vec ! [ String :: from( "e" ) ] ,
89
+ vec ! [ String :: from( "f" ) ] ,
90
+ ) ) {
91
+ Err ( DirectoryError :: DirNotExists ) => { }
92
+ Err ( err) => panic ! ( "should have NoPathProvided, got {:?}" , err) ,
93
+ Ok ( ( ) ) => panic ! ( "should not be fine" ) ,
94
+ }
95
+
96
+ // destination's parent does not exists
97
+ match futures:: executor:: block_on ( test_create_then_move_to (
98
+ & db,
99
+ & directory,
100
+ vec ! [ String :: from( "a" ) , String :: from( "g" ) ] ,
101
+ vec ! [ String :: from( "i-do-not-exists-yet" ) , String :: from( "z" ) ] ,
102
+ ) ) {
103
+ Err ( DirectoryError :: ParentDirDoesNotExists ) => { }
104
+ Err ( err) => panic ! ( "should have ParentDirDoesNotExists, got {:?}" , err) ,
105
+ Ok ( ( ) ) => panic ! ( "should not be fine" ) ,
106
+ }
107
+
108
+ // destination not empty
109
+ match futures:: executor:: block_on ( test_create_then_move_to (
110
+ & db,
111
+ & directory,
112
+ vec ! [ String :: from( "a" ) , String :: from( "g" ) ] ,
113
+ vec ! [ String :: from( "a" ) , String :: from( "g" ) ] ,
114
+ ) ) {
115
+ Err ( DirectoryError :: BadDestinationDirectory ) => { }
116
+ Err ( err) => panic ! ( "should have BadDestinationDirectory, got {:?}" , err) ,
117
+ Ok ( ( ) ) => panic ! ( "should not be fine" ) ,
118
+ }
119
+
120
+ // cannot move to a children of the old-path
121
+ match futures:: executor:: block_on ( test_create_then_move_to (
122
+ & db,
123
+ & directory,
124
+ vec ! [ String :: from( "a" ) , String :: from( "g" ) ] ,
125
+ vec ! [ String :: from( "a" ) , String :: from( "g" ) , String :: from( "s" ) ] ,
126
+ ) ) {
127
+ Err ( DirectoryError :: BadDestinationDirectory ) => { }
128
+ Err ( err) => panic ! ( "should have BadDestinationDirectory, got {:?}" , err) ,
129
+ Ok ( ( ) ) => panic ! ( "should not be fine" ) ,
130
+ }
60
131
}
61
132
62
- async fn test_move_to (
133
+ async fn test_create_then_move_to (
63
134
db : & Database ,
64
135
directory : & DirectoryLayer ,
65
136
old_paths : Vec < String > ,
66
137
new_paths : Vec < String > ,
67
138
) -> Result < ( ) , DirectoryError > {
139
+ eprintln ! (
140
+ "moving {:?} to {:?}" ,
141
+ old_paths. to_owned( ) ,
142
+ new_paths. to_owned( )
143
+ ) ;
68
144
let trx = db. create_trx ( ) ?;
69
145
let create_output = directory. create_or_open ( & trx, old_paths. to_owned ( ) ) . await ?;
70
146
@@ -91,6 +167,38 @@ async fn test_move_to(
91
167
Ok ( ( ) )
92
168
}
93
169
170
+ async fn test_move_to (
171
+ db : & Database ,
172
+ directory : & DirectoryLayer ,
173
+ old_paths : Vec < String > ,
174
+ new_paths : Vec < String > ,
175
+ ) -> Result < ( ) , DirectoryError > {
176
+ eprintln ! (
177
+ "moving {:?} to {:?}" ,
178
+ old_paths. to_owned( ) ,
179
+ new_paths. to_owned( )
180
+ ) ;
181
+ let trx = db. create_trx ( ) ?;
182
+
183
+ let move_output = directory
184
+ . move_to ( & trx, old_paths. to_owned ( ) , new_paths. to_owned ( ) )
185
+ . await ?;
186
+ assert ! ( move_output) ;
187
+
188
+ trx. commit ( ) . await . expect ( "could not commit" ) ;
189
+ let trx = db. create_trx ( ) ?;
190
+
191
+ directory. open ( & trx, new_paths) . await ?;
192
+
193
+ trx. commit ( ) . await . expect ( "could not commit" ) ;
194
+ let trx = db. create_trx ( ) ?;
195
+
196
+ let open_old_path = directory. open ( & trx, old_paths) . await ;
197
+ assert ! ( open_old_path. is_err( ) ) ;
198
+
199
+ Ok ( ( ) )
200
+ }
201
+
94
202
async fn test_create_then_open_async (
95
203
db : & Database ,
96
204
directory : & DirectoryLayer ,
0 commit comments