mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-08 03:36:37 +00:00
Speedup binstalk-git-repo-api unit testing (#1731)
* Share `remote::Client` between tests when in cargo-test Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Run rate-limited binstalk-git-repo-api test in serial Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Update client-side rate limit to 1 request per 300ms Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Reduce test cases in `rate_limited_test_has_release_artifact_and_download_artifacts` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add `cargo-nextest` that I forgot Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix unit testing: Pass auth-token to restful API to avoid rate limit Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
4d7a91aa4c
commit
6622bf1ae3
7 changed files with 75 additions and 35 deletions
|
@ -38,6 +38,7 @@ fn get_api_endpoint() -> &'static Url {
|
|||
pub(super) fn issue_restful_api<T>(
|
||||
client: &remote::Client,
|
||||
path: &[&str],
|
||||
auth_token: Option<&str>,
|
||||
) -> impl Future<Output = Result<T, GhApiError>> + Send + Sync + 'static
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
|
@ -50,11 +51,16 @@ where
|
|||
|
||||
debug!("Getting restful API: {url}");
|
||||
|
||||
let future = client
|
||||
let mut request_builder = client
|
||||
.get(url)
|
||||
.header("Accept", "application/vnd.github+json")
|
||||
.header("X-GitHub-Api-Version", "2022-11-28")
|
||||
.send(false);
|
||||
.header("X-GitHub-Api-Version", "2022-11-28");
|
||||
|
||||
if let Some(auth_token) = auth_token {
|
||||
request_builder = request_builder.bearer_auth(&auth_token);
|
||||
}
|
||||
|
||||
let future = request_builder.send(false);
|
||||
|
||||
async move {
|
||||
let response = check_http_status_and_header(future.await?)?;
|
||||
|
|
|
@ -73,8 +73,13 @@ pub(super) fn fetch_release_artifacts_restful_api(
|
|||
repo: GhRepo { owner, repo },
|
||||
tag,
|
||||
}: &GhRelease,
|
||||
auth_token: Option<&str>,
|
||||
) -> impl Future<Output = Result<Artifacts, GhApiError>> + Send + Sync + 'static {
|
||||
issue_restful_api(client, &["repos", owner, repo, "releases", "tags", tag])
|
||||
issue_restful_api(
|
||||
client,
|
||||
&["repos", owner, repo, "releases", "tags", tag],
|
||||
auth_token,
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
|
@ -44,8 +44,9 @@ impl RepoInfo {
|
|||
pub(super) fn fetch_repo_info_restful_api(
|
||||
client: &remote::Client,
|
||||
GhRepo { owner, repo }: &GhRepo,
|
||||
auth_token: Option<&str>,
|
||||
) -> impl Future<Output = Result<Option<RepoInfo>, GhApiError>> + Send + Sync + 'static {
|
||||
issue_restful_api(client, &["repos", owner, repo])
|
||||
issue_restful_api(client, &["repos", owner, repo], auth_token)
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue