()
| 1365 | |
| 1366 | #[tokio::test] |
| 1367 | async fn test_response_clone_error() { |
| 1368 | let mock_server = MockServer::start().await; |
| 1369 | |
| 1370 | Mock::given(matchers::path("some-path/")) |
| 1371 | .respond_with(ResponseTemplate::new(200).set_body_string("Hello".to_string())) |
| 1372 | .mount(&mock_server) |
| 1373 | .await; |
| 1374 | |
| 1375 | test_async_with_opts( |
| 1376 | |ctx| { |
| 1377 | llrt_stream_web::init(&ctx).unwrap(); |
| 1378 | crate::init(&ctx).unwrap(); |
| 1379 | Box::pin(async move { |
| 1380 | let globals = ctx.globals(); |
| 1381 | let run = async { |
| 1382 | let fetch: Function = globals.get("fetch")?; |
| 1383 | let options = Object::new(ctx.clone())?; |
| 1384 | options.set("method", "GET")?; |
| 1385 | let url = format!("http://{}/some-path/", mock_server.address().clone()); |
| 1386 | |
| 1387 | let response_promise: Promise = fetch.call((url, options.clone()))?; |
| 1388 | let response: Class<Response> = response_promise.into_future().await?; |
| 1389 | |
| 1390 | // Cloning a response with unconsumed Incoming body should work via tee |
| 1391 | let cloned = response.borrow().clone(ctx.clone())?; |
| 1392 | let cloned = Class::instance(ctx.clone(), cloned)?; |
| 1393 | let text1: String = Response::text(This(response.clone()), ctx.clone())? |
| 1394 | .into_future() |
| 1395 | .await?; |
| 1396 | let text2: String = Response::text(This(cloned), ctx.clone())? |
| 1397 | .into_future() |
| 1398 | .await?; |
| 1399 | assert_eq!(text1, "Hello"); |
| 1400 | assert_eq!(text2, "Hello"); |
| 1401 | |
| 1402 | // Cloning after body is consumed should fail |
| 1403 | let clone_result = response.borrow().clone(ctx.clone()); |
| 1404 | assert!(clone_result.is_err()); |
| 1405 | Ok(()) |
| 1406 | }; |
| 1407 | run.await.catch(&ctx).unwrap(); |
| 1408 | }) |
| 1409 | }, |
| 1410 | TestOptions::new().no_pending_jobs(), |
| 1411 | ) |
| 1412 | .await; |
| 1413 | } |
| 1414 | |
| 1415 | #[tokio::test] |
| 1416 | async fn test_response_compressed_body_stream() { |
nothing calls this directly
no test coverage detected