Skip to content

Commit 7d3f1a7

Browse files
bors[bot]Romil Punetha
and
Romil Punetha
authored
Merge #391
391: Uses big_S to cleanup tests r=bidoubiwa a=romilpunetha # Pull Request ## Related issue Fixes #388 ## What does this PR do? - Adds big_S crate as a dev dependency to be used for tests ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Romil Punetha <[email protected]>
2 parents 13da4de + 9aefce4 commit 7d3f1a7

File tree

8 files changed

+76
-82
lines changed

8 files changed

+76
-82
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ yew = "0.18"
5555
lazy_static = "1.4"
5656
web-sys = "0.3"
5757
console_error_panic_hook = "0.1"
58+
big_s = "1.0.2"

src/client.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
use std::{collections::HashMap, time::Duration};
2+
3+
use serde::Deserialize;
4+
use serde_json::{json, Value};
5+
use time::OffsetDateTime;
6+
17
use crate::{
28
errors::*,
39
indexes::*,
@@ -7,10 +13,6 @@ use crate::{
713
tasks::{Task, TasksQuery, TasksResults},
814
utils::async_sleep,
915
};
10-
use serde::Deserialize;
11-
use serde_json::{json, Value};
12-
use std::{collections::HashMap, time::Duration};
13-
use time::OffsetDateTime;
1416

1517
/// The top-level struct of the SDK, representing a client containing [indexes](../indexes/struct.Index.html).
1618
#[derive(Debug, Clone)]
@@ -881,14 +883,18 @@ pub struct Version {
881883

882884
#[cfg(test)]
883885
mod tests {
886+
use std::mem;
887+
888+
use big_s::S;
889+
use mockito::mock;
890+
use time::OffsetDateTime;
891+
892+
use meilisearch_test_macro::meilisearch_test;
893+
884894
use crate::{
885895
client::*,
886896
key::{Action, KeyBuilder},
887897
};
888-
use meilisearch_test_macro::meilisearch_test;
889-
use mockito::mock;
890-
use std::mem;
891-
use time::OffsetDateTime;
892898

893899
#[meilisearch_test]
894900
async fn test_methods_has_qualified_version_as_header() {
@@ -1000,7 +1006,6 @@ mod tests {
10001006
}
10011007

10021008
#[meilisearch_test]
1003-
10041009
async fn test_error_delete_key(mut client: Client, name: String) {
10051010
// ==> accessing a key that does not exist
10061011
let error = client.delete_key("invalid_key").await.unwrap_err();
@@ -1065,7 +1070,7 @@ mod tests {
10651070
key.expires_at.unwrap().unix_timestamp(),
10661071
expires_at.unix_timestamp()
10671072
);
1068-
assert_eq!(key.indexes, vec!["*".to_string()]);
1073+
assert_eq!(key.indexes, vec![S("*")]);
10691074

10701075
client.delete_key(key).await.unwrap();
10711076
}
@@ -1120,7 +1125,7 @@ mod tests {
11201125
key.with_name("test_update_key");
11211126
let mut key = client.create_key(key).await.unwrap();
11221127

1123-
let name = "new name".to_string();
1128+
let name = S("new name");
11241129
key.with_description(&description);
11251130
key.with_name(&name);
11261131

@@ -1141,7 +1146,7 @@ mod tests {
11411146
.try_make_index(&client)
11421147
.unwrap();
11431148

1144-
assert_eq!(index.uid.to_string(), index_uid);
1149+
assert_eq!(index.uid, index_uid);
11451150
index
11461151
.delete()
11471152
.await?

src/documents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ mod tests {
433433
async fn test_generate_index(client: Client) -> Result<(), Error> {
434434
let index: Index = MovieClips::generate_index(&client).await.unwrap();
435435

436-
assert_eq!(index.uid.to_string(), "movie_clips");
436+
assert_eq!(index.uid, "movie_clips");
437437

438438
index
439439
.delete()

src/indexes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,7 @@ pub struct IndexesResults {
15651565
mod tests {
15661566
use super::*;
15671567

1568+
use big_s::S;
15681569
use meilisearch_test_macro::meilisearch_test;
15691570
use serde_json::json;
15701571

@@ -1583,7 +1584,7 @@ mod tests {
15831584
});
15841585

15851586
let idx = Index {
1586-
uid: "test_from_value".to_string(),
1587+
uid: S("test_from_value"),
15871588
primary_key: None,
15881589
created_at: Some(t),
15891590
updated_at: Some(t),

src/search.rs

+39-55
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ impl<'a> SearchQuery<'a> {
387387
#[cfg(test)]
388388
mod tests {
389389
use crate::{client::*, search::*};
390+
use big_s::S;
390391
use meilisearch_test_macro::meilisearch_test;
391392
use serde::{Deserialize, Serialize};
392393
use serde_json::{json, Map, Value};
@@ -414,16 +415,16 @@ mod tests {
414415

415416
async fn setup_test_index(client: &Client, index: &Index) -> Result<(), Error> {
416417
let t0 = index.add_documents(&[
417-
Document { id: 0, kind: "text".into(), value: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.".to_string(), nested: Nested { child: "first".to_string() } },
418-
Document { id: 1, kind: "text".into(), value: "dolor sit amet, consectetur adipiscing elit".to_string(), nested: Nested { child: "second".to_string() } },
419-
Document { id: 2, kind: "title".into(), value: "The Social Network".to_string(), nested: Nested { child: "third".to_string() } },
420-
Document { id: 3, kind: "title".into(), value: "Harry Potter and the Sorcerer's Stone".to_string(), nested: Nested { child: "fourth".to_string() } },
421-
Document { id: 4, kind: "title".into(), value: "Harry Potter and the Chamber of Secrets".to_string(), nested: Nested { child: "fift".to_string() } },
422-
Document { id: 5, kind: "title".into(), value: "Harry Potter and the Prisoner of Azkaban".to_string(), nested: Nested { child: "sixth".to_string() } },
423-
Document { id: 6, kind: "title".into(), value: "Harry Potter and the Goblet of Fire".to_string(), nested: Nested { child: "seventh".to_string() } },
424-
Document { id: 7, kind: "title".into(), value: "Harry Potter and the Order of the Phoenix".to_string(), nested: Nested { child: "eighth".to_string() } },
425-
Document { id: 8, kind: "title".into(), value: "Harry Potter and the Half-Blood Prince".to_string(), nested: Nested { child: "ninth".to_string() } },
426-
Document { id: 9, kind: "title".into(), value: "Harry Potter and the Deathly Hallows".to_string(), nested: Nested { child: "tenth".to_string() } },
418+
Document { id: 0, kind: "text".into(), value: S("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."), nested: Nested { child: S("first") } },
419+
Document { id: 1, kind: "text".into(), value: S("dolor sit amet, consectetur adipiscing elit"), nested: Nested { child: S("second") } },
420+
Document { id: 2, kind: "title".into(), value: S("The Social Network"), nested: Nested { child: S("third") } },
421+
Document { id: 3, kind: "title".into(), value: S("Harry Potter and the Sorcerer's Stone"), nested: Nested { child: S("fourth") } },
422+
Document { id: 4, kind: "title".into(), value: S("Harry Potter and the Chamber of Secrets"), nested: Nested { child: S("fift") } },
423+
Document { id: 5, kind: "title".into(), value: S("Harry Potter and the Prisoner of Azkaban"), nested: Nested { child: S("sixth") } },
424+
Document { id: 6, kind: "title".into(), value: S("Harry Potter and the Goblet of Fire"), nested: Nested { child: S("seventh") } },
425+
Document { id: 7, kind: "title".into(), value: S("Harry Potter and the Order of the Phoenix"), nested: Nested { child: S("eighth") } },
426+
Document { id: 8, kind: "title".into(), value: S("Harry Potter and the Half-Blood Prince"), nested: Nested { child: S("ninth") } },
427+
Document { id: 9, kind: "title".into(), value: S("Harry Potter and the Deathly Hallows"), nested: Nested { child: S("tenth") } },
427428
], None).await?;
428429
let t1 = index.set_filterable_attributes(["kind", "value"]).await?;
429430
let t2 = index.set_sortable_attributes(["title"]).await?;
@@ -442,7 +443,7 @@ mod tests {
442443

443444
let res = query.execute::<Document>().await.unwrap();
444445

445-
assert_eq!(res.query, "space".to_string());
446+
assert_eq!(res.query, S("space"));
446447
assert_eq!(res.limit, 21);
447448
assert_eq!(res.offset, 42);
448449
Ok(())
@@ -467,11 +468,9 @@ mod tests {
467468
assert_eq!(
468469
&Document {
469470
id: 1,
470-
value: "dolor sit amet, consectetur adipiscing elit".to_string(),
471-
kind: "text".to_string(),
472-
nested: Nested {
473-
child: "second".to_string()
474-
}
471+
value: S("dolor sit amet, consectetur adipiscing elit"),
472+
kind: S("text"),
473+
nested: Nested { child: S("second") }
475474
},
476475
&results.hits[0].result
477476
);
@@ -619,12 +618,9 @@ mod tests {
619618
assert_eq!(
620619
&Document {
621620
id: 0,
622-
value: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do…"
623-
.to_string(),
624-
kind: "text".to_string(),
625-
nested: Nested {
626-
child: "first".to_string()
627-
}
621+
value: S("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do…"),
622+
kind: S("text"),
623+
nested: Nested { child: S("first") }
628624
},
629625
results.hits[0].formatted_result.as_ref().unwrap()
630626
);
@@ -636,11 +632,9 @@ mod tests {
636632
assert_eq!(
637633
&Document {
638634
id: 0,
639-
value: "Lorem ipsum dolor sit amet…".to_string(),
640-
kind: "text".to_string(),
641-
nested: Nested {
642-
child: "first".to_string()
643-
}
635+
value: S("Lorem ipsum dolor sit amet…"),
636+
kind: S("text"),
637+
nested: Nested { child: S("first") }
644638
},
645639
results.hits[0].formatted_result.as_ref().unwrap()
646640
);
@@ -658,9 +652,9 @@ mod tests {
658652
let results: SearchResults<Document> = index.execute_query(&query).await?;
659653
assert_eq!(&Document {
660654
id: 0,
661-
value: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.".to_string(),
662-
kind: "text".to_string(),
663-
nested: Nested { child: "first".to_string() }
655+
value: S("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
656+
kind: S("text"),
657+
nested: Nested { child: S("first") }
664658
},
665659
results.hits[0].formatted_result.as_ref().unwrap());
666660

@@ -672,11 +666,9 @@ mod tests {
672666
assert_eq!(
673667
&Document {
674668
id: 0,
675-
value: "Lorem ipsum dolor sit amet…".to_string(),
676-
kind: "text".to_string(),
677-
nested: Nested {
678-
child: "first".to_string()
679-
}
669+
value: S("Lorem ipsum dolor sit amet…"),
670+
kind: S("text"),
671+
nested: Nested { child: S("first") }
680672
},
681673
results.hits[0].formatted_result.as_ref().unwrap()
682674
);
@@ -698,11 +690,9 @@ mod tests {
698690
assert_eq!(
699691
&Document {
700692
id: 0,
701-
value: "(ꈍᴗꈍ) sed do eiusmod tempor incididunt ut(ꈍᴗꈍ)".to_string(),
702-
kind: "text".to_string(),
703-
nested: Nested {
704-
child: "first".to_string()
705-
}
693+
value: S("(ꈍᴗꈍ) sed do eiusmod tempor incididunt ut(ꈍᴗꈍ)"),
694+
kind: S("text"),
695+
nested: Nested { child: S("first") }
706696
},
707697
results.hits[0].formatted_result.as_ref().unwrap()
708698
);
@@ -726,11 +716,9 @@ mod tests {
726716
assert_eq!(
727717
&Document {
728718
id: 2,
729-
value: "The (⊃。•́‿•̀。)⊃ Social ⊂(´• ω •`⊂) Network".to_string(),
730-
kind: "title".to_string(),
731-
nested: Nested {
732-
child: "third".to_string()
733-
}
719+
value: S("The (⊃。•́‿•̀。)⊃ Social ⊂(´• ω •`⊂) Network"),
720+
kind: S("title"),
721+
nested: Nested { child: S("third") }
734722
},
735723
results.hits[0].formatted_result.as_ref().unwrap()
736724
);
@@ -749,11 +737,9 @@ mod tests {
749737
assert_eq!(
750738
&Document {
751739
id: 1,
752-
value: "<em>dolor</em> sit amet, consectetur adipiscing elit".to_string(),
753-
kind: "<em>text</em>".to_string(),
754-
nested: Nested {
755-
child: "first".to_string()
756-
}
740+
value: S("<em>dolor</em> sit amet, consectetur adipiscing elit"),
741+
kind: S("<em>text</em>"),
742+
nested: Nested { child: S("first") }
757743
},
758744
results.hits[0].formatted_result.as_ref().unwrap(),
759745
);
@@ -765,11 +751,9 @@ mod tests {
765751
assert_eq!(
766752
&Document {
767753
id: 1,
768-
value: "<em>dolor</em> sit amet, consectetur adipiscing elit".to_string(),
769-
kind: "text".to_string(),
770-
nested: Nested {
771-
child: "first".to_string()
772-
}
754+
value: S("<em>dolor</em> sit amet, consectetur adipiscing elit"),
755+
kind: S("text"),
756+
nested: Nested { child: S("first") }
773757
},
774758
results.hits[0].formatted_result.as_ref().unwrap()
775759
);

src/task_info.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ mod test {
8686
errors::{ErrorCode, ErrorType},
8787
indexes::Index,
8888
};
89+
use big_s::S;
8990
use meilisearch_test_macro::meilisearch_test;
9091
use serde::{Deserialize, Serialize};
9192
use std::time::Duration;
@@ -137,12 +138,12 @@ mod test {
137138
Document {
138139
id: 0,
139140
kind: "title".into(),
140-
value: "The Social Network".to_string(),
141+
value: S("The Social Network"),
141142
},
142143
Document {
143144
id: 1,
144145
kind: "title".into(),
145-
value: "Harry Potter and the Sorcerer's Stone".to_string(),
146+
value: S("Harry Potter and the Sorcerer's Stone"),
146147
},
147148
],
148149
None,

src/tasks.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ mod test {
475475
client::*,
476476
errors::{ErrorCode, ErrorType},
477477
};
478+
use big_s::S;
478479
use meilisearch_test_macro::meilisearch_test;
479480
use mockito::mock;
480481
use serde::{Deserialize, Serialize};
@@ -600,12 +601,12 @@ mod test {
600601
Document {
601602
id: 0,
602603
kind: "title".into(),
603-
value: "The Social Network".to_string(),
604+
value: S("The Social Network"),
604605
},
605606
Document {
606607
id: 1,
607608
kind: "title".into(),
608-
value: "Harry Potter and the Sorcerer's Stone".to_string(),
609+
value: S("Harry Potter and the Sorcerer's Stone"),
609610
},
610611
],
611612
None,

0 commit comments

Comments
 (0)