Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: track caller for .crate file publish verification #14992

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions crates/cargo-test-support/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ where
}

/// Check the `cargo publish` API call
#[track_caller]
pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_files: &[&str]) {
let new_path = registry::api_path().join("api/v1/crates/new");
_validate_upload(
Expand All @@ -90,6 +91,7 @@ pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_
}

/// Check the `cargo publish` API call, with file contents
#[track_caller]
pub fn validate_upload_with_contents(
expected_json: &str,
expected_crate_name: &str,
Expand All @@ -107,6 +109,7 @@ pub fn validate_upload_with_contents(
}

/// Check the `cargo publish` API call to the alternative test registry
#[track_caller]
pub fn validate_alt_upload(
expected_json: &str,
expected_crate_name: &str,
Expand All @@ -122,6 +125,7 @@ pub fn validate_alt_upload(
);
}

#[track_caller]
fn _validate_upload(
new_path: &Path,
expected_json: &str,
Expand All @@ -142,6 +146,7 @@ fn _validate_upload(
);
}

#[track_caller]
fn read_new_post(new_path: &Path) -> (Vec<u8>, Vec<u8>) {
let mut f = File::open(new_path).unwrap();

Expand Down Expand Up @@ -170,6 +175,7 @@ fn read_new_post(new_path: &Path) -> (Vec<u8>, Vec<u8>) {
/// - `expected_contents` should be a list of `(file_name, contents)` tuples
/// to validate the contents of the given file. Only the listed files will
/// be checked (others will be ignored).
#[track_caller]
pub fn validate_crate_contents(
reader: impl Read,
expected_crate_name: &str,
Expand All @@ -185,17 +191,19 @@ pub fn validate_crate_contents(
)
}

#[track_caller]
fn validate_crate_contents_(
reader: impl Read,
expected_crate_name: &str,
expected_files: &[&str],
expected_contents: InMemoryDir,
) {
let mut rdr = GzDecoder::new(reader);
assert_eq!(
rdr.header().unwrap().filename().unwrap(),
expected_crate_name.as_bytes()
);
snapbox::assert_data_eq!(rdr.header().unwrap().filename().unwrap(), {
let expected: snapbox::Data = expected_crate_name.into();
expected.raw()
});

let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
let mut ar = Archive::new(&contents[..]);
Expand Down
Loading