From 471fcd91c14e3fd26f0e4e62d63886a5cd5c94a5 Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Fri, 25 Oct 2024 10:16:54 -0400 Subject: [PATCH] Switch to async tests and add download test --- .gitignore | 1 + chromiumoxide_fetcher/Cargo.toml | 5 ++- chromiumoxide_fetcher/tests/verify.rs | 60 +++++++++++++++++++++------ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 7fb4c14b..cdb0a8ac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /download Cargo.lock .idea/ +.cache/ diff --git a/chromiumoxide_fetcher/Cargo.toml b/chromiumoxide_fetcher/Cargo.toml index 1eabc8ca..fc598355 100644 --- a/chromiumoxide_fetcher/Cargo.toml +++ b/chromiumoxide_fetcher/Cargo.toml @@ -12,7 +12,10 @@ readme = "../README.md" include = ["src/**/*", "LICENSE-*"] [dev-dependencies] -ureq = "2.10.0" +reqwest = { version = "0.12", features = [ + "rustls-tls", +], default-features = false } +tokio = { version = "1", features = ["rt", "fs", "macros"] } [dependencies] thiserror = "1" diff --git a/chromiumoxide_fetcher/tests/verify.rs b/chromiumoxide_fetcher/tests/verify.rs index 732ef375..6aa330a5 100644 --- a/chromiumoxide_fetcher/tests/verify.rs +++ b/chromiumoxide_fetcher/tests/verify.rs @@ -1,9 +1,14 @@ -use chromiumoxide_fetcher::{Platform, Revision, CURRENT_REVISION}; +use chromiumoxide_fetcher::{BrowserFetcherOptions, Platform, Revision, CURRENT_REVISION}; +use reqwest::{IntoUrl, Response, StatusCode}; + +pub async fn head(url: T) -> reqwest::Result { + reqwest::Client::builder().build()?.head(url).send().await +} // Check if the chosen revision has a build available for all platforms. // That not always the case, that is why we need to make sure of it. -#[test] -fn verify_revision_available() { +#[tokio::test] +async fn verify_revision_available() { for platform in &[ Platform::Linux, Platform::Mac, @@ -11,11 +16,11 @@ fn verify_revision_available() { Platform::Win32, Platform::Win64, ] { - let res = - ureq::head(&platform.download_url("https://storage.googleapis.com", &CURRENT_REVISION)) - .call(); + let res = head(&platform.download_url("https://storage.googleapis.com", &CURRENT_REVISION)) + .await + .unwrap(); - if res.is_err() { + if res.status() != StatusCode::OK { panic!( "Revision {} is not available for {:?}", CURRENT_REVISION, platform @@ -25,8 +30,8 @@ fn verify_revision_available() { } #[ignore] -#[test] -fn find_revision_available() { +#[tokio::test] +async fn find_revision_available() { let min = 1355000; // Enter the minimum revision let max = 1356013; // Enter the maximum revision @@ -40,12 +45,13 @@ fn find_revision_available() { Platform::Win32, Platform::Win64, ] { - let res = ureq::head( + let res = head( &platform.download_url("https://storage.googleapis.com", &Revision::from(revision)), ) - .call(); + .await + .unwrap(); - if res.is_err() { + if res.status() != StatusCode::OK { println!("Revision {} is not available for {:?}", revision, platform); continue 'outer; } @@ -55,3 +61,33 @@ fn find_revision_available() { break; } } + +#[ignore] +#[tokio::test] +async fn download_revision() { + let path = "./.cache"; + + tokio::fs::create_dir(path).await.unwrap(); + + for platform in &[ + Platform::Linux, + Platform::Mac, + Platform::MacArm, + Platform::Win32, + Platform::Win64, + ] { + let revision = chromiumoxide_fetcher::BrowserFetcher::new( + BrowserFetcherOptions::builder() + .with_revision(CURRENT_REVISION) + .with_path(path) + .with_platform(*platform) + .build() + .unwrap(), + ) + .fetch() + .await + .unwrap(); + + println!("Downloaded revision {} for {:?}", revision, platform); + } +}