| 520 | |
| 521 | #[tokio::test] |
| 522 | async fn test_fetch_function() { |
| 523 | let mock_server = MockServer::start().await; |
| 524 | let welcome_message = "Hello, LLRT!"; |
| 525 | |
| 526 | Mock::given(matchers::path("expect/200/")) |
| 527 | .respond_with( |
| 528 | ResponseTemplate::new(200) |
| 529 | .set_body_string(String::from_utf8(welcome_message.into()).unwrap()), |
| 530 | ) |
| 531 | .mount(&mock_server) |
| 532 | .await; |
| 533 | |
| 534 | Mock::given(matchers::path("expect/301/")) |
| 535 | .respond_with(ResponseTemplate::new(301).insert_header( |
| 536 | "location", |
| 537 | format!("http://{}/{}", mock_server.address(), "expect/200/"), |
| 538 | )) |
| 539 | .mount(&mock_server) |
| 540 | .await; |
| 541 | |
| 542 | Mock::given(matchers::path("expect/302/")) |
| 543 | .respond_with(ResponseTemplate::new(302).insert_header( |
| 544 | "location", |
| 545 | format!("http://{}/{}", mock_server.address(), "expect/200/"), |
| 546 | )) |
| 547 | .mount(&mock_server) |
| 548 | .await; |
| 549 | |
| 550 | Mock::given(matchers::path("expect/303/")) |
| 551 | .respond_with(ResponseTemplate::new(303).insert_header( |
| 552 | "location", |
| 553 | format!("http://{}/{}", mock_server.address(), "expect/200/"), |
| 554 | )) |
| 555 | .mount(&mock_server) |
| 556 | .await; |
| 557 | |
| 558 | Mock::given(matchers::path("expect/304/")) |
| 559 | .respond_with(ResponseTemplate::new(304).insert_header( |
| 560 | "location", |
| 561 | format!("http://{}/{}", mock_server.address(), "expect/200/"), |
| 562 | )) |
| 563 | .mount(&mock_server) |
| 564 | .await; |
| 565 | |
| 566 | let mut data: Vec<u8> = Vec::new(); |
| 567 | llrt_compression::zstd::encoder(welcome_message.as_bytes(), 3) |
| 568 | .unwrap() |
| 569 | .read_to_end(&mut data) |
| 570 | .unwrap(); |
| 571 | Mock::given(matchers::path("content-encoding/zstd/")) |
| 572 | .respond_with( |
| 573 | ResponseTemplate::new(200) |
| 574 | .append_header("content-encoding", "zstd") |
| 575 | .set_body_raw(data.to_owned(), "text/plain"), |
| 576 | ) |
| 577 | .mount(&mock_server) |
| 578 | .await; |
| 579 | |