This is an automated email from the ASF dual-hosted git repository. xuanwo pushed a commit to branch http-send-reqwest-wasm in repository https://gitbox.apache.org/repos/asf/opendal-reqsign.git
commit 11442eed96c667618d6c90f5b95e54bbc482f021 Author: Xuanwo <[email protected]> AuthorDate: Sun Oct 19 16:34:41 2025 +0800 fix ci Signed-off-by: Xuanwo <[email protected]> --- .github/workflows/ci.yml | 12 ++++++++++- context/http-send-reqwest/Cargo.toml | 5 ++++- .../http-send-reqwest/examples/custom_client.rs | 12 +++++++++++ context/http-send-reqwest/tests/wasm.rs | 25 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a13abda..76b3b61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,9 +85,19 @@ jobs: env: RUST_LOG: DEBUG RUST_BACKTRACE: full - - name: Doc Test run: cargo test --doc --all-features --workspace env: RUST_LOG: DEBUG RUST_BACKTRACE: full + + wasm_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Run wasm tests + env: + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: wasm-bindgen-test-runner + run: | + rustup target add wasm32-unknown-unknown + cargo test --target wasm32-unknown-unknown -p reqsign-http-send-reqwest --test wasm diff --git a/context/http-send-reqwest/Cargo.toml b/context/http-send-reqwest/Cargo.toml index c5a211a..4b5a21c 100644 --- a/context/http-send-reqwest/Cargo.toml +++ b/context/http-send-reqwest/Cargo.toml @@ -38,9 +38,12 @@ reqsign-core = { workspace = true } reqwest = { workspace = true, default-features = false } [dev-dependencies] -tokio = { version = "1", features = ["macros", "rt-multi-thread"] } reqwest = { workspace = true, default-features = false, features = ["default-tls"] } +wasm-bindgen-test = { version = "0.3" } [target.'cfg(target_arch = "wasm32")'.dependencies] futures-channel = { version = "0.3" } wasm-bindgen-futures = { version = "0.4" } + +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/context/http-send-reqwest/examples/custom_client.rs b/context/http-send-reqwest/examples/custom_client.rs index 1124ff5..546ef85 100644 --- a/context/http-send-reqwest/examples/custom_client.rs +++ b/context/http-send-reqwest/examples/custom_client.rs @@ -15,13 +15,20 @@ // specific language governing permissions and limitations // under the License. +#[cfg(not(target_arch = "wasm32"))] use anyhow::Result; +#[cfg(not(target_arch = "wasm32"))] use bytes::Bytes; +#[cfg(not(target_arch = "wasm32"))] use reqsign_core::{Context, OsEnv}; +#[cfg(not(target_arch = "wasm32"))] use reqsign_http_send_reqwest::ReqwestHttpSend; +#[cfg(not(target_arch = "wasm32"))] use reqwest::Client; +#[cfg(not(target_arch = "wasm32"))] use std::time::Duration; +#[cfg(not(target_arch = "wasm32"))] #[tokio::main] async fn main() -> Result<()> { // Create a custom reqwest client with specific configuration @@ -95,3 +102,8 @@ async fn main() -> Result<()> { Ok(()) } + +#[cfg(target_arch = "wasm32")] +fn main() { + panic!("custom_client example is not supported on wasm targets"); +} diff --git a/context/http-send-reqwest/tests/wasm.rs b/context/http-send-reqwest/tests/wasm.rs new file mode 100644 index 0000000..d214ac3 --- /dev/null +++ b/context/http-send-reqwest/tests/wasm.rs @@ -0,0 +1,25 @@ +#![cfg(target_arch = "wasm32")] + +use bytes::Bytes; +use http::Request; +use reqsign_core::HttpSend; +use reqsign_http_send_reqwest::ReqwestHttpSend; +use wasm_bindgen_test::*; + +#[wasm_bindgen_test] +async fn http_send_returns_error_for_unreachable_host() { + let client = reqwest::Client::new(); + let http_send = ReqwestHttpSend::new(client); + + let req = Request::builder() + .method("GET") + .uri("https://nonexistent.invalid") + .body(Bytes::new()) + .expect("request builds"); + + let result = http_send.http_send(req).await; + assert!( + result.is_err(), + "expected unreachable host to produce error" + ); +}
