mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-17 08:06:38 +00:00
Refactor: Create parameter-ised test_has_release_artifact
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
345255a65f
commit
4ffaf8c805
1 changed files with 54 additions and 71 deletions
|
@ -326,11 +326,6 @@ mod test {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_gh_api_client_cargo_audit_v_0_17_6() {
|
|
||||||
test_specific_release(&RELEASE, ARTIFACTS).await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_extract_artifact_from_str(s: &str) -> Option<GhReleaseArtifact> {
|
fn try_extract_artifact_from_str(s: &str) -> Option<GhReleaseArtifact> {
|
||||||
|
@ -490,81 +485,69 @@ mod test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn test_specific_release(release: &GhRelease, artifacts: &[&str]) {
|
#[tokio::test]
|
||||||
|
async fn test_has_release_artifact() {
|
||||||
|
const RELEASES: [(GhRelease, &[&str]); 2] = [
|
||||||
|
(
|
||||||
|
cargo_audit_v_0_17_6::RELEASE,
|
||||||
|
cargo_audit_v_0_17_6::ARTIFACTS,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
cargo_audit_v_0_17_6::RELEASE,
|
||||||
|
cargo_audit_v_0_17_6::ARTIFACTS,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
const NON_EXISTENT_RELEASES: [GhRelease; 1] = [GhRelease {
|
||||||
|
repo: GhRepo {
|
||||||
|
owner: CompactString::new_inline("cargo-bins"),
|
||||||
|
repo: CompactString::new_inline("cargo-binstall"),
|
||||||
|
},
|
||||||
|
// We are currently at v0.20.1 and we would never release
|
||||||
|
// anything older than v0.20.1
|
||||||
|
tag: CompactString::new_inline("v0.18.2"),
|
||||||
|
}];
|
||||||
|
|
||||||
init_logger();
|
init_logger();
|
||||||
|
|
||||||
for client in create_client().await {
|
for client in create_client().await {
|
||||||
eprintln!("In client {client:?}");
|
eprintln!("In client {client:?}");
|
||||||
|
|
||||||
|
for (release, artifacts) in RELEASES {
|
||||||
for artifact_name in artifacts {
|
for artifact_name in artifacts {
|
||||||
let res = client
|
client
|
||||||
.has_release_artifact(GhReleaseArtifact {
|
.has_release_artifact(GhReleaseArtifact {
|
||||||
release: release.clone(),
|
release: release.clone(),
|
||||||
artifact_name: artifact_name.to_compact_string(),
|
artifact_name: artifact_name.to_compact_string(),
|
||||||
})
|
})
|
||||||
.await;
|
.await
|
||||||
|
.unwrap()
|
||||||
assert!(
|
.unwrap();
|
||||||
matches!(res, Ok(Some(_)) | Err(GhApiError::RateLimit { .. })),
|
|
||||||
"for '{artifact_name}': answer is {:#?}",
|
|
||||||
res
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = client
|
assert_eq!(
|
||||||
|
client
|
||||||
.has_release_artifact(GhReleaseArtifact {
|
.has_release_artifact(GhReleaseArtifact {
|
||||||
release: release.clone(),
|
release: release.clone(),
|
||||||
artifact_name: "123z".to_compact_string(),
|
artifact_name: "123z".to_compact_string(),
|
||||||
})
|
})
|
||||||
.await;
|
.await
|
||||||
|
.unwrap(),
|
||||||
assert!(
|
None
|
||||||
matches!(res, Ok(None) | Err(GhApiError::RateLimit { .. })),
|
|
||||||
"res = {:#?}",
|
|
||||||
res
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
for release in NON_EXISTENT_RELEASES {
|
||||||
async fn test_gh_api_client_cargo_binstall_v0_20_1() {
|
assert_eq!(
|
||||||
test_specific_release(
|
client
|
||||||
&cargo_binstall_v0_20_1::RELEASE,
|
|
||||||
cargo_binstall_v0_20_1::ARTIFACTS,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_gh_api_client_cargo_binstall_no_such_release() {
|
|
||||||
init_logger();
|
|
||||||
|
|
||||||
for client in create_client().await {
|
|
||||||
let release = GhRelease {
|
|
||||||
repo: GhRepo {
|
|
||||||
owner: "cargo-bins".to_compact_string(),
|
|
||||||
repo: "cargo-binstall".to_compact_string(),
|
|
||||||
},
|
|
||||||
// We are currently at v0.20.1 and we would never release
|
|
||||||
// anything older than v0.20.1
|
|
||||||
tag: "v0.18.2".to_compact_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let err = client
|
|
||||||
.has_release_artifact(GhReleaseArtifact {
|
.has_release_artifact(GhReleaseArtifact {
|
||||||
release,
|
release,
|
||||||
artifact_name: "1234".to_compact_string(),
|
artifact_name: "1234".to_compact_string(),
|
||||||
})
|
})
|
||||||
.await;
|
.await
|
||||||
|
.unwrap(),
|
||||||
assert!(
|
None
|
||||||
matches!(
|
|
||||||
err,
|
|
||||||
Ok(None) | Err(GhApiError::NotFound | GhApiError::RateLimit { .. })
|
|
||||||
),
|
|
||||||
"err = {:#?}",
|
|
||||||
err
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue