@@ -129,29 +129,37 @@ fn _validate_upload(
129
129
expected_files : & [ & str ] ,
130
130
expected_contents : & [ ( & str , & str ) ] ,
131
131
) {
132
+ let ( actual_json, krate_bytes) = read_new_post ( new_path) ;
133
+
134
+ snapbox:: assert_data_eq!( actual_json, expected_json. is_json( ) ) ;
135
+
136
+ // Verify the tarball.
137
+ validate_crate_contents (
138
+ & krate_bytes[ ..] ,
139
+ expected_crate_name,
140
+ expected_files,
141
+ expected_contents,
142
+ ) ;
143
+ }
144
+
145
+ fn read_new_post ( new_path : & Path ) -> ( Vec < u8 > , Vec < u8 > ) {
132
146
let mut f = File :: open ( new_path) . unwrap ( ) ;
147
+
133
148
// 32-bit little-endian integer of length of JSON data.
134
149
let json_sz = read_le_u32 ( & mut f) . expect ( "read json length" ) ;
135
150
let mut json_bytes = vec ! [ 0 ; json_sz as usize ] ;
136
151
f. read_exact ( & mut json_bytes) . expect ( "read JSON data" ) ;
137
152
138
- snapbox:: assert_data_eq!( json_bytes, expected_json. is_json( ) ) ;
139
-
140
153
// 32-bit little-endian integer of length of crate file.
141
154
let crate_sz = read_le_u32 ( & mut f) . expect ( "read crate length" ) ;
142
155
let mut krate_bytes = vec ! [ 0 ; crate_sz as usize ] ;
143
156
f. read_exact ( & mut krate_bytes) . expect ( "read crate data" ) ;
157
+
144
158
// Check at end.
145
159
let current = f. seek ( SeekFrom :: Current ( 0 ) ) . unwrap ( ) ;
146
160
assert_eq ! ( f. seek( SeekFrom :: End ( 0 ) ) . unwrap( ) , current) ;
147
161
148
- // Verify the tarball.
149
- validate_crate_contents (
150
- & krate_bytes[ ..] ,
151
- expected_crate_name,
152
- expected_files,
153
- expected_contents,
154
- ) ;
162
+ ( json_bytes, krate_bytes)
155
163
}
156
164
157
165
/// Checks the contents of a `.crate` file.
0 commit comments