From 343a677566d39a25a439ddf7b295135d5e5eee8c Mon Sep 17 00:00:00 2001 From: "Andrey \"MOU\" Larionov" Date: Mon, 10 Oct 2022 11:04:46 +0200 Subject: [PATCH] Fix formatting and apply clippy suggestion --- meilisearch-http/tests/common/encoder.rs | 20 +++++++++++++------ meilisearch-http/tests/common/index.rs | 10 ++++++++-- .../tests/documents/add_documents.rs | 13 +++++------- .../tests/documents/update_documents.rs | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/meilisearch-http/tests/common/encoder.rs b/meilisearch-http/tests/common/encoder.rs index 41d560253..78d6051d1 100644 --- a/meilisearch-http/tests/common/encoder.rs +++ b/meilisearch-http/tests/common/encoder.rs @@ -1,10 +1,10 @@ -use std::io::Write; use actix_http::header::TryIntoHeaderPair; use bytes::Bytes; use flate2::write::{GzEncoder, ZlibEncoder}; use flate2::Compression; +use std::io::Write; -#[derive(Clone,Copy)] +#[derive(Clone, Copy)] pub enum Encoder { Plain, Gzip, @@ -17,18 +17,24 @@ impl Encoder { match self { Self::Gzip => { let mut encoder = GzEncoder::new(Vec::new(), Compression::default()); - encoder.write_all(&body.into()).expect("Failed to encode request body"); + encoder + .write_all(&body.into()) + .expect("Failed to encode request body"); encoder.finish().expect("Failed to encode request body") } Self::Deflate => { let mut encoder = ZlibEncoder::new(Vec::new(), Compression::default()); - encoder.write_all(&body.into()).expect("Failed to encode request body"); + encoder + .write_all(&body.into()) + .expect("Failed to encode request body"); encoder.finish().unwrap() } Self::Plain => Vec::from(body.into()), Self::Brotli => { let mut encoder = brotli::CompressorWriter::new(Vec::new(), 32 * 1024, 3, 22); - encoder.write_all(&body.into()).expect("Failed to encode request body"); + encoder + .write_all(&body.into()) + .expect("Failed to encode request body"); encoder.flush().expect("Failed to encode request body"); encoder.into_inner() } @@ -45,6 +51,8 @@ impl Encoder { } pub fn iterator() -> impl Iterator { - [Self::Plain, Self::Gzip, Self::Deflate, Self::Brotli].iter().copied() + [Self::Plain, Self::Gzip, Self::Deflate, Self::Brotli] + .iter() + .copied() } } diff --git a/meilisearch-http/tests/common/index.rs b/meilisearch-http/tests/common/index.rs index c084d1f09..43534074d 100644 --- a/meilisearch-http/tests/common/index.rs +++ b/meilisearch-http/tests/common/index.rs @@ -190,7 +190,9 @@ impl Index<'_> { pub async fn update_settings(&self, settings: Value) -> (Value, StatusCode) { let url = format!("/indexes/{}/settings", urlencode(self.uid.as_ref())); - self.service.patch_encoded(url, settings, self.encoder).await + self.service + .patch_encoded(url, settings, self.encoder) + .await } pub async fn delete_settings(&self) -> (Value, StatusCode) { @@ -230,7 +232,11 @@ impl Index<'_> { pub async fn search_get(&self, query: Value) -> (Value, StatusCode) { let params = yaup::to_string(&query).unwrap(); - let url = format!("/indexes/{}/search?{}", urlencode(self.uid.as_ref()), params); + let url = format!( + "/indexes/{}/search?{}", + urlencode(self.uid.as_ref()), + params + ); self.service.get(url).await } diff --git a/meilisearch-http/tests/documents/add_documents.rs b/meilisearch-http/tests/documents/add_documents.rs index f4cb3d36f..48ef6276b 100644 --- a/meilisearch-http/tests/documents/add_documents.rs +++ b/meilisearch-http/tests/documents/add_documents.rs @@ -1,10 +1,10 @@ use crate::common::{GetAllDocumentsOptions, Server}; use actix_web::test; +use crate::common::encoder::Encoder; use meilisearch_http::{analytics, create_app}; use serde_json::{json, Value}; use time::{format_description::well_known::Rfc3339, OffsetDateTime}; -use crate::common::encoder::Encoder; /// This is the basic usage of our API and every other tests uses the content-type application/json #[actix_rt::test] @@ -115,7 +115,7 @@ async fn add_single_document_gzip_encoded() { server.service.options, analytics::MockAnalytics::new(&server.service.options).0 )) - .await; + .await; // post let document = serde_json::to_string(&document).unwrap(); let encoder = Encoder::Gzip; @@ -164,19 +164,18 @@ async fn add_single_document_with_every_encoding() { server.service.options, analytics::MockAnalytics::new(&server.service.options).0 )) - .await; + .await; // post - let mut task_uid = 0; let document = serde_json::to_string(&document).unwrap(); - for encoder in Encoder::iterator() { + for (task_uid, encoder) in Encoder::iterator().enumerate() { let mut req = test::TestRequest::post() .uri("/indexes/dog/documents") .set_payload(encoder.encode(document.clone())) .insert_header(("content-type", "application/json")); req = match encoder.header() { Some(header) => req.insert_header(header), - None => req + None => req, }; let req = req.to_request(); let res = test::call_service(&app, req).await; @@ -185,9 +184,7 @@ async fn add_single_document_with_every_encoding() { let response: Value = serde_json::from_slice(&body).unwrap_or_default(); assert_eq!(status_code, 202); assert_eq!(response["taskUid"], task_uid); - task_uid += 1; } - } /// any other content-type is must be refused diff --git a/meilisearch-http/tests/documents/update_documents.rs b/meilisearch-http/tests/documents/update_documents.rs index da932ed26..99d700f9f 100644 --- a/meilisearch-http/tests/documents/update_documents.rs +++ b/meilisearch-http/tests/documents/update_documents.rs @@ -1,7 +1,7 @@ use crate::common::{GetAllDocumentsOptions, Server}; -use serde_json::json; use crate::common::encoder::Encoder; +use serde_json::json; #[actix_rt::test] async fn error_document_update_create_index_bad_uid() {