Skip to content

Commit 2c96728

Browse files
committed
refactor(test): Pull out new POST parsing
1 parent ab361f2 commit 2c96728

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

crates/cargo-test-support/src/publish.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,29 +129,37 @@ fn _validate_upload(
129129
expected_files: &[&str],
130130
expected_contents: &[(&str, &str)],
131131
) {
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>) {
132146
let mut f = File::open(new_path).unwrap();
147+
133148
// 32-bit little-endian integer of length of JSON data.
134149
let json_sz = read_le_u32(&mut f).expect("read json length");
135150
let mut json_bytes = vec![0; json_sz as usize];
136151
f.read_exact(&mut json_bytes).expect("read JSON data");
137152

138-
snapbox::assert_data_eq!(json_bytes, expected_json.is_json());
139-
140153
// 32-bit little-endian integer of length of crate file.
141154
let crate_sz = read_le_u32(&mut f).expect("read crate length");
142155
let mut krate_bytes = vec![0; crate_sz as usize];
143156
f.read_exact(&mut krate_bytes).expect("read crate data");
157+
144158
// Check at end.
145159
let current = f.seek(SeekFrom::Current(0)).unwrap();
146160
assert_eq!(f.seek(SeekFrom::End(0)).unwrap(), current);
147161

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)
155163
}
156164

157165
/// Checks the contents of a `.crate` file.

0 commit comments

Comments
 (0)