A better Rust ATProto crate
at main 2.1 kB view raw
1#![cfg(all( 2 feature = "streaming", 3 feature = "reqwest-client", 4 not(target_arch = "wasm32") 5))] 6 7use jacquard_common::http_client::HttpClientExt; 8use jacquard_common::stream::{StreamError, StreamErrorKind}; 9use n0_future::StreamExt; 10 11#[tokio::test] 12async fn streaming_response_delivers_all_bytes() { 13 let client = reqwest::Client::new(); 14 15 let request = http::Request::builder() 16 .uri("https://www.rust-lang.org/") 17 .body(vec![]) 18 .unwrap(); 19 20 let response = client.send_http_streaming(request).await.unwrap(); 21 assert!(response.status().is_success()); 22 23 let (_parts, body) = response.into_parts(); 24 let stream = body.into_inner(); 25 26 // Pin the stream for iteration 27 tokio::pin!(stream); 28 29 let mut total = 0; 30 31 while let Some(result) = stream.next().await { 32 let chunk = result.unwrap(); 33 total += chunk.len(); 34 } 35 36 // Just verify we got some bytes 37 assert!(total > 0); 38} 39 40// #[tokio::test] 41// async fn streaming_upload_sends_all_chunks() { 42// let client = reqwest::Client::new(); 43 44// let chunks = vec![ 45// Bytes::from("chunk1"), 46// Bytes::from("chunk2"), 47// Bytes::from("chunk3"), 48// ]; 49// let body_stream = futures::stream::iter(chunks.clone()); 50 51// // Build a complete request and extract parts 52// let request: http::Request<Vec<u8>> = http::Request::builder() 53// .method(http::Method::POST) 54// .uri("https://httpbingo.org/post") 55// .body(vec![]) 56// .unwrap(); 57// let (parts, _) = request.into_parts(); 58 59// let response = client 60// .send_http_bidirectional(parts, body_stream) 61// .await 62// .unwrap(); 63// assert!(response.status().is_success()); 64// } 65 66#[tokio::test] 67async fn stream_error_preserves_source() { 68 let io_error = std::io::Error::new(std::io::ErrorKind::ConnectionReset, "reset"); 69 let stream_error = StreamError::transport(io_error); 70 71 assert_eq!(stream_error.kind(), &StreamErrorKind::Transport); 72 assert!(stream_error.source().is_some()); 73}