Share remote::Client between tests when in cargo-test

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-06-12 19:47:59 +10:00
parent 2feac66e14
commit ec279cd1d5
No known key found for this signature in database
GPG key ID: 76D1E687CA3C4928
3 changed files with 17 additions and 8 deletions

1
Cargo.lock generated
View file

@ -354,6 +354,7 @@ version = "0.0.0"
dependencies = [
"binstalk-downloader",
"compact_str",
"once_cell",
"percent-encoding",
"serde",
"serde-tuple-vec-map",

View file

@ -26,3 +26,4 @@ url = "2.3.1"
[dev-dependencies]
binstalk-downloader = { version = "0.11.1", path = "../binstalk-downloader" }
tracing-subscriber = "0.3"
once_cell = "1"

View file

@ -313,6 +313,7 @@ impl GhApiClient {
mod test {
use super::*;
use compact_str::{CompactString, ToCompactString};
use once_cell::sync::OnceCell;
use std::{env, num::NonZeroU16, time::Duration};
use tokio::time::sleep;
use tracing::subscriber::set_global_default;
@ -490,14 +491,20 @@ mod test {
}
fn create_remote_client() -> remote::Client {
remote::Client::new(
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
None,
NonZeroU16::new(200).unwrap(),
1.try_into().unwrap(),
[],
)
.unwrap()
static CLIENT: OnceCell<remote::Client> = OnceCell::new();
CLIENT
.get_or_init(|| {
remote::Client::new(
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
None,
NonZeroU16::new(200).unwrap(),
1.try_into().unwrap(),
[],
)
.unwrap()
})
.clone()
}
/// Mark this as an async fn so that you won't accidentally use it in