@@ -29,6 +29,14 @@ fn rand_bytes_with_blake2b() -> Result<(Vec<u8>, String), FailureError> {
29
29
Ok ( ( bytes. to_vec ( ) , hasher. finalize ( ) . to_hex ( ) [ ..32 ] . into ( ) ) )
30
30
}
31
31
32
+ fn clean_up_manifest_and_parent ( manifest_pbuf : & PathBuf ) {
33
+ let parent_dir = std:: path:: Path :: new ( manifest_pbuf)
34
+ . parent ( )
35
+ . expect ( "failed to get parent dir" ) ;
36
+ std:: fs:: remove_file ( manifest_pbuf) . expect ( "failed to remove manifest file" ) ;
37
+ std:: fs:: remove_dir_all ( parent_dir) . expect ( "failed to remove parent dir" ) ;
38
+ }
39
+
32
40
#[ test]
33
41
fn nothing_to_fetch_if_cache_fully_hydrated ( ) -> Result < ( ) , FailureError > {
34
42
let mut manifest: BTreeMap < String , ParameterData > = BTreeMap :: new ( ) ;
@@ -48,7 +56,7 @@ fn nothing_to_fetch_if_cache_fully_hydrated() -> Result<(), FailureError> {
48
56
49
57
let manifest_pbuf = tmp_manifest ( Some ( manifest) ) ?;
50
58
51
- let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf) )
59
+ let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf. clone ( ) ) )
52
60
. with_session_timeout_ms ( 1000 )
53
61
. with_file_and_bytes ( "aaa.vk" , & mut aaa_bytes)
54
62
. build ( ) ;
@@ -57,6 +65,9 @@ fn nothing_to_fetch_if_cache_fully_hydrated() -> Result<(), FailureError> {
57
65
session. exp_string ( "file is up to date" ) ?;
58
66
session. exp_string ( "no outdated files, exiting" ) ?;
59
67
68
+ clean_up_manifest_and_parent ( & manifest_pbuf) ;
69
+ std:: fs:: remove_dir_all ( session. _cache_dir . path ( ) ) ?;
70
+
60
71
Ok ( ( ) )
61
72
}
62
73
@@ -75,7 +86,7 @@ fn prompts_to_download_if_file_in_manifest_is_missing() -> Result<(), FailureErr
75
86
76
87
let manifest_pbuf = tmp_manifest ( Some ( manifest) ) ?;
77
88
78
- let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf) )
89
+ let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf. clone ( ) ) )
79
90
. with_session_timeout_ms ( 1000 )
80
91
. build ( ) ;
81
92
@@ -84,6 +95,9 @@ fn prompts_to_download_if_file_in_manifest_is_missing() -> Result<(), FailureErr
84
95
session. exp_string ( "Select files to be downloaded" ) ?;
85
96
session. exp_string ( "aaa.vk (1 KiB)" ) ?;
86
97
98
+ clean_up_manifest_and_parent ( & manifest_pbuf) ;
99
+ std:: fs:: remove_dir_all ( session. _cache_dir . path ( ) ) ?;
100
+
87
101
Ok ( ( ) )
88
102
}
89
103
@@ -105,7 +119,7 @@ fn prompts_to_download_if_file_checksum_does_not_match_manifest() -> Result<(),
105
119
106
120
let manifest_pbuf = tmp_manifest ( Some ( manifest) ) ?;
107
121
108
- let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf) )
122
+ let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf. clone ( ) ) )
109
123
. with_session_timeout_ms ( 1000 )
110
124
. with_file_and_bytes ( "aaa.vk" , & mut aaa_bytes)
111
125
. build ( ) ;
@@ -116,6 +130,9 @@ fn prompts_to_download_if_file_checksum_does_not_match_manifest() -> Result<(),
116
130
session. exp_string ( "Select files to be downloaded" ) ?;
117
131
session. exp_string ( "aaa.vk (1 KiB)" ) ?;
118
132
133
+ clean_up_manifest_and_parent ( & manifest_pbuf) ;
134
+ std:: fs:: remove_dir_all ( session. _cache_dir . path ( ) ) ?;
135
+
119
136
Ok ( ( ) )
120
137
}
121
138
@@ -143,7 +160,7 @@ fn fetches_vk_even_if_sector_size_does_not_match() -> Result<(), FailureError> {
143
160
144
161
let manifest_pbuf = tmp_manifest ( Some ( manifest) ) ?;
145
162
146
- let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf) )
163
+ let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf. clone ( ) ) )
147
164
. with_session_timeout_ms ( 1000 )
148
165
. whitelisted_sector_sizes ( vec ! [ "6666" . to_string( ) , "4444" . to_string( ) ] )
149
166
. build ( ) ;
@@ -153,6 +170,9 @@ fn fetches_vk_even_if_sector_size_does_not_match() -> Result<(), FailureError> {
153
170
session. exp_string ( "determining if file is out of date: aaa.vk" ) ?;
154
171
session. exp_string ( "file not found, marking for download" ) ?;
155
172
173
+ clean_up_manifest_and_parent ( & manifest_pbuf) ;
174
+ std:: fs:: remove_dir_all ( session. _cache_dir . path ( ) ) ?;
175
+
156
176
Ok ( ( ) )
157
177
}
158
178
@@ -165,22 +185,29 @@ fn invalid_json_path_produces_error() -> Result<(), FailureError> {
165
185
session. exp_string ( "using json file: /invalid/path" ) ?;
166
186
session. exp_string ( "failed to open json file, exiting" ) ?;
167
187
188
+ std:: fs:: remove_dir_all ( session. _cache_dir . path ( ) ) ?;
189
+
168
190
Ok ( ( ) )
169
191
}
170
192
171
193
#[ test]
172
194
fn invalid_json_produces_error ( ) -> Result < ( ) , FailureError > {
173
195
let manifest_pbuf = tmp_manifest ( None ) ?;
174
196
175
- let mut file = File :: create ( & manifest_pbuf) ?;
176
- file. write_all ( b"invalid json" ) ?;
197
+ {
198
+ let mut file = File :: create ( & manifest_pbuf) ?;
199
+ file. write_all ( b"invalid json" ) ?;
200
+ }
177
201
178
- let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf) )
202
+ let mut session = ParamFetchSessionBuilder :: new ( Some ( manifest_pbuf. clone ( ) ) )
179
203
. with_session_timeout_ms ( 1000 )
180
204
. build ( ) ;
181
205
182
206
session. exp_string ( "failed to parse json file, exiting" ) ?;
183
207
208
+ clean_up_manifest_and_parent ( & manifest_pbuf) ;
209
+ std:: fs:: remove_dir_all ( session. _cache_dir . path ( ) ) ?;
210
+
184
211
Ok ( ( ) )
185
212
}
186
213
@@ -203,5 +230,7 @@ fn no_json_path_uses_default_manifest() -> Result<(), FailureError> {
203
230
) ) ?;
204
231
}
205
232
233
+ std:: fs:: remove_dir_all ( session. _cache_dir . path ( ) ) ?;
234
+
206
235
Ok ( ( ) )
207
236
}
0 commit comments