MCPcopy Create free account
hub / github.com/awslabs/llrt / test_response_stream

Function test_response_stream

modules/llrt_fetch/src/response.rs:1327–1364  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1325
1326 #[tokio::test]
1327 async fn test_response_stream() {
1328 let mock_server = MockServer::start().await;
1329 let welcome_message = "Hello, LLRT!";
1330
1331 Mock::given(matchers::path("some-path/"))
1332 .respond_with(ResponseTemplate::new(200).set_body_string(welcome_message.to_string()))
1333 .mount(&mock_server)
1334 .await;
1335
1336 test_async_with_opts(
1337 |ctx| {
1338 crate::init(&ctx).unwrap();
1339 Box::pin(async move {
1340 let globals = ctx.globals();
1341 let run = async {
1342 let fetch: Function = globals.get("fetch")?;
1343 let options = Object::new(ctx.clone())?;
1344 options.set("method", "GET")?;
1345 let url = format!("http://{}/some-path/", mock_server.address().clone());
1346
1347 let response_promise: Promise = fetch.call((url, options.clone()))?;
1348 let response: Class<Response> = response_promise.into_future().await?;
1349
1350 let response_text: String =
1351 Response::text(This(response.clone()), ctx.clone())?
1352 .into_future()
1353 .await?;
1354 assert_eq!(response.borrow().status(), 200);
1355 assert_eq!(response_text, welcome_message);
1356 Ok(())
1357 };
1358 run.await.catch(&ctx).unwrap();
1359 })
1360 },
1361 TestOptions::new().no_pending_jobs(),
1362 )
1363 .await;
1364 }
1365
1366 #[tokio::test]
1367 async fn test_response_clone_error() {

Callers

nothing calls this directly

Calls 9

test_async_with_optsFunction · 0.85
no_pending_jobsMethod · 0.80
initFunction · 0.70
startFunction · 0.50
to_stringMethod · 0.45
getMethod · 0.45
cloneMethod · 0.45
setMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected