From e68d86d6b6d85151eb458de69038d060132f0974 Mon Sep 17 00:00:00 2001 From: Filip Bachul Date: Thu, 11 May 2023 20:51:06 +0200 Subject: [PATCH 1/2] tests: add unit test for `PayloadTooLarge` --- meilisearch/src/extractors/payload.rs | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/meilisearch/src/extractors/payload.rs b/meilisearch/src/extractors/payload.rs index 5e7e9cf7e..75d314965 100644 --- a/meilisearch/src/extractors/payload.rs +++ b/meilisearch/src/extractors/payload.rs @@ -71,3 +71,40 @@ impl Stream for Payload { } } } + +#[cfg(test)] +mod tests { + use actix_http::encoding::Decoder as Decompress; + use actix_http::BoxedPayloadStream; + use bytes::Bytes; + use futures_util::StreamExt; + use meili_snap::snapshot; + + use super::*; + + #[actix_rt::test] + async fn example_test() { + let stream = futures::stream::iter(vec![ + Ok(Bytes::from("1")), + Ok(Bytes::from("2")), + Ok(Bytes::from("3")), + Ok(Bytes::from("4")), + ]); + let boxed_stream: BoxedPayloadStream = Box::pin(stream); + let actix_payload = dev::Payload::from(boxed_stream); + + let payload = Payload { + limit: 3, + remaining: 3, + payload: Decompress::new(actix_payload, actix_http::ContentEncoding::Identity), + }; + + let mut enumerated_payload_stream = payload.enumerate(); + + while let Some((idx, chunk)) = enumerated_payload_stream.next().await { + if idx == 3 { + snapshot!(chunk.unwrap_err(), @"The provided payload reached the size limit. The maximum accepted payload size is 3 B."); + } + } + } +} From 64b11f45d702822a9073d46712fe052958fd5e68 Mon Sep 17 00:00:00 2001 From: Filip Bachul Date: Tue, 16 May 2023 09:24:49 +0200 Subject: [PATCH 2/2] fix test name --- meilisearch/src/extractors/payload.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meilisearch/src/extractors/payload.rs b/meilisearch/src/extractors/payload.rs index 75d314965..6e0d51468 100644 --- a/meilisearch/src/extractors/payload.rs +++ b/meilisearch/src/extractors/payload.rs @@ -83,7 +83,7 @@ mod tests { use super::*; #[actix_rt::test] - async fn example_test() { + async fn payload_to_large() { let stream = futures::stream::iter(vec![ Ok(Bytes::from("1")), Ok(Bytes::from("2")),