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

Switch to async tests and add download test #248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/download
Cargo.lock
.idea/
.cache/
5 changes: 4 additions & 1 deletion chromiumoxide_fetcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
60 changes: 48 additions & 12 deletions chromiumoxide_fetcher/tests/verify.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
use chromiumoxide_fetcher::{Platform, Revision, CURRENT_REVISION};
use chromiumoxide_fetcher::{BrowserFetcherOptions, Platform, Revision, CURRENT_REVISION};
use reqwest::{IntoUrl, Response, StatusCode};

pub async fn head<T: IntoUrl>(url: T) -> reqwest::Result<Response> {
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,
Platform::MacArm,
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
Expand All @@ -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

Expand All @@ -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;
}
Expand All @@ -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);
}
}
Loading