#![cfg(all(
feature = "streaming",
feature = "reqwest-client",
not(target_arch = "wasm32")
))]
use jacquard_common::http_client::HttpClientExt;
use jacquard_common::stream::{StreamError, StreamErrorKind};
use n0_future::StreamExt;
#[tokio::test]
async fn streaming_response_delivers_all_bytes() {
let client = reqwest::Client::new();
let request = http::Request::builder()
.uri("https://www.rust-lang.org/")
.body(vec![])
.unwrap();
let response = client.send_http_streaming(request).await.unwrap();
assert!(response.status().is_success());
let (_parts, body) = response.into_parts();
let stream = body.into_inner();
tokio::pin!(stream);
let mut total = 0;
while let Some(result) = stream.next().await {
let chunk = result.unwrap();
total += chunk.len();
}
assert!(total > 0);
}
#[tokio::test]
async fn stream_error_preserves_source() {
let io_error = std::io::Error::new(std::io::ErrorKind::ConnectionReset, "reset");
let stream_error = StreamError::transport(io_error);
assert_eq!(stream_error.kind(), &StreamErrorKind::Transport);
assert!(stream_error.source().is_some());
}