Skip to content

Commit 8dc417a

Browse files
bors[bot]meili-botcurquizairevoire
authored
Merge #214
214: Changes related to the next MeiliSearch release (v0.25.0) r=curquiza a=meili-bot Related to this issue: meilisearch/integration-guides#157 This PR: - gathers the changes related to the next MeiliSearch release (v0.25.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases). - might eventually contain test failures until the MeiliSearch v0.25.0 is out. ⚠️ This PR should NOT be merged until the next release of MeiliSearch (v0.25.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Clémentine Urquizar - curqui <[email protected]> Co-authored-by: Tamo <[email protected]> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com> Co-authored-by: Irevoire <[email protected]> Co-authored-by: Clémentine Urquizar <[email protected]>
2 parents 9187baa + 25cd089 commit 8dc417a

File tree

20 files changed

+2447
-1303
lines changed

20 files changed

+2447
-1303
lines changed

.code-samples.meilisearch.yaml

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,14 @@ search_post_1: |-
5858
.execute()
5959
.await
6060
.unwrap();
61-
get_update_1: |-
62-
// You can get the status of a `Progress` object:
63-
let status: Status = progress.get_status().await.unwrap();
64-
65-
// Or you can use index to get an update status using its `update_id`:
66-
let status: Status = client.index("movies").get_update(1).await.unwrap();
67-
get_all_updates_1: |-
68-
let status: Vec<ProgressStatus> = client.index("movies").get_all_updates().await.unwrap();
69-
get_keys_1: |-
70-
let keys: Keys = client.get_keys().await.unwrap();
61+
get_task_by_index_1: |-
62+
let task: Task = client.index("movies").get_task(1).await.unwrap();
63+
get_all_tasks_by_index_1: |-
64+
let tasks: Vec<Task> = client.index("movies").get_tasks().await.unwrap();
65+
get_all_tasks_1: |-
66+
let tasks: Vec<Task> = client.get_tasks().await.unwrap();
67+
get_task_1: |-
68+
let task: Task = client.get_task(1).await.unwrap();
7169
get_settings_1: |-
7270
let settings: Settings = client.index("movies").get_settings().await.unwrap();
7371
update_settings_1: |-
@@ -685,3 +683,48 @@ geosearch_guide_sort_usage_2: |-
685683
.execute()
686684
.await
687685
.unwrap();
686+
get_one_key_1: |-
687+
let key = client.get_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4").await.unwrap();
688+
get_all_keys_1: |-
689+
let keys = client.get_keys().await.unwrap();
690+
create_a_key_1: |-
691+
let mut key_options = KeyBuilder::new("Add documents: Products API key");
692+
key_options.with_action(Action::DocumentsAdd)
693+
.with_expires_at("2042-04-02T00:42:42Z")
694+
.with_index("products");
695+
let new_key = client.create_key(key_options).await.unwrap();
696+
update_a_key_1: |-
697+
let key = client.get_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4").await.unwrap();
698+
key.description = "Manage documents: Products/Reviews API key".to_string();
699+
key.actions = vec![Action::DocumentsAdd, Action::DocumentsDelete];
700+
key.indexes = vec!["products".to_string(), "reviews".to_string()];
701+
key.expires_at = Some("2042-04-02T00:42:42Z".to_string());
702+
let updated_key = client.update_key(&key);
703+
delete_a_key_1: |-
704+
let key = client.get_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4").await.unwrap();
705+
client.delete_key(&key);
706+
authorization_header_1:
707+
let client = Client::new("http://localhost:7700", "masterKey");
708+
let keys = client.get_keys().await.unwrap();
709+
security_guide_search_key_1: |-
710+
let client = Client::new("http://localhost:7700", "apiKey");
711+
let result = client.index("patient_medical_records").search().execute().await.unwrap();
712+
security_guide_update_key_1: |-
713+
let client = Client::new("http://localhost:7700", "masterKey");
714+
let key = client.get_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4").await.unwrap();
715+
key.indexes = vec!["doctors".to_string()];
716+
let updated_key = client.update_key(&key);
717+
security_guide_create_key_1: |-
718+
let client = Client::new("http://localhost:7700", "masterKey");
719+
let mut key_options = KeyBuilder::new("Search patient records key");
720+
key_options.with_action(Action::Search)
721+
.with_expires_at("2023-01-01T00:00:00Z")
722+
.with_index("patient_medical_records");
723+
let new_key = client.create_key(key_options).await.unwrap();
724+
security_guide_list_keys_1: |-
725+
let client = Client::new("http://localhost:7700", "masterKey");
726+
let keys = client.get_keys().await.unwrap();
727+
security_guide_delete_key_1: |-
728+
let client = Client::new("http://localhost:7700", "masterKey");
729+
let key = client.get_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4").await.unwrap();
730+
client.delete_key(&key);

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ jobs:
2424
- name: Build
2525
run: cargo build --verbose
2626
- name: Meilisearch (latest version) setup with Docker
27-
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics=true --master-key=masterKey
27+
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics --master-key=masterKey
2828
- name: Run tests
29-
run: cargo test --verbose -- --test-threads=1
29+
run: cargo test --verbose
3030

3131
linter:
3232
name: clippy-check

CONTRIBUTING.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume
2929

3030
### Tests <!-- omit in toc -->
3131

32-
All the tests are documentation tests.<br>
33-
Since they are all making operations on the Meilisearch server, running all the tests simultaneously would cause panics.
34-
35-
To run the tests one by one, run:
32+
To run the tests, run:
3633

3734
```bash
3835
# Tests
3936
curl -L https://install.meilisearch.com | sh # download Meilisearch
40-
./meilisearch --master-key=masterKey --no-analytics=true # run Meilisearch
41-
cargo test -- --test-threads=1
37+
./meilisearch --master-key=masterKey --no-analytics # run Meilisearch
38+
cargo test
4239
```
4340

41+
There is two kind of tests, documentation tests and unit tests.
42+
If you need to write or read the unit tests you should consider reading this
43+
[readme](meilisearch-test-macro/README.md) about our custom testing macro.
44+
4445
Also, the WASM example compilation should be checked:
4546

4647
```bash

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ readme = "README.md"
99
repository = "https://github.com/meilisearch/meilisearch-sdk"
1010

1111
[dependencies]
12+
async-trait = "0.1.51"
1213
serde_json = "1.0"
1314
log = "0.4"
1415
serde = { version = "1.0", features = ["derive"] }
@@ -32,6 +33,7 @@ sync = []
3233
env_logger = "0.9"
3334
futures-await-test = "0.3"
3435
futures = "0.3"
36+
meilisearch-test-macro = { path = "meilisearch-test-macro" }
3537

3638
# The following dependencies are required for examples
3739
wasm-bindgen = "0.2"

README.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,28 @@ fn main() { block_on(async move {
117117

118118
// Add some movies in the index. If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
119119
movies.add_documents(&[
120-
Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]},
121-
Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]},
122-
Movie{id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()]},
123-
Movie{id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()]},
124-
Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]},
125-
Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]},
120+
Movie { id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()] },
121+
Movie { id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()] },
122+
Movie { id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()] },
123+
Movie { id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()] },
124+
Movie { id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()] },
125+
Movie { id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()] },
126126
], Some("id")).await.unwrap();
127127
})}
128128
```
129129

130+
With the `uid`, you can check the status (`enqueued`, `processing`, `succeeded` or `failed`) of your documents addition using the [task](https://docs.meilisearch.com/reference/api/tasks.html#get-task).
131+
130132
#### Basic Search <!-- omit in TOC -->
131133

132134
```rust
133135
// Meilisearch is typo-tolerant:
134-
println!("{:?}", client.index("movies").search().with_query("caorl").execute::<Movie>().await.unwrap().hits);
136+
println!("{:?}", client.index("movies_2").search().with_query("caorl").execute::<Movie>().await.unwrap().hits);
135137
```
136138

137139
Output:
138140
```
139-
[Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"]}]
141+
[Movie { id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"] }]
140142
```
141143

142144
Json output:
@@ -157,7 +159,14 @@ Json output:
157159
#### Custom Search <!-- omit in toc -->
158160

159161
```rust
160-
println!("{:?}", client.index("movies").search().with_query("phil").with_attributes_to_highlight(Selectors::Some(&["*"])).execute::<Movie>().await.unwrap().hits);
162+
let search_result = client.index("movies_3")
163+
.search()
164+
.with_query("phil")
165+
.with_attributes_to_highlight(Selectors::Some(&["*"]))
166+
.execute::<Movie>()
167+
.await
168+
.unwrap();
169+
println!("{:?}", search_result.hits);
161170
```
162171

163172
Json output:
@@ -189,23 +198,26 @@ index setting.
189198
```rust
190199
let filterable_attributes = [
191200
"id",
192-
"genres"
201+
"genres",
193202
];
194-
client.index("movies").set_filterable_attributes(&filterable_attributes).await.unwrap();
203+
client.index("movies_4").set_filterable_attributes(&filterable_attributes).await.unwrap();
195204
```
196205

197206
You only need to perform this operation once.
198207

199-
Note that Meilisearch will rebuild your index whenever you update `filterableAttributes`.
200-
Depending on the size of your dataset, this might take time. You can track the whole process
201-
using the [update
202-
status](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status).
208+
Note that Meilisearch will rebuild your index whenever you update `filterableAttributes`. Depending on the size of your dataset, this might take time. You can track the process using the [tasks](https://docs.meilisearch.com/reference/api/tasks.html#get-task)).
203209

204210
Then, you can perform the search:
205211

206212
```rust
207-
println!("{:?}", client.index("movies").search().with_query("wonder").with_filter("id > 1 AND genres = Action")
208-
.execute::<Movie>().await.unwrap().hits);
213+
let search_result = client.index("movies_5")
214+
.search()
215+
.with_query("wonder")
216+
.with_filter("id > 1 AND genres = Action")
217+
.execute::<Movie>()
218+
.await
219+
.unwrap();
220+
println!("{:?}", search_result.hits);
209221
```
210222

211223
Json output:
@@ -238,7 +250,7 @@ WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extensi
238250

239251
## 🤖 Compatibility with Meilisearch
240252

241-
This package only guarantees the compatibility with the [version v0.24.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.24.0).
253+
This package only guarantees the compatibility with the [version v0.25.0 of MeiliSearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.25.0).
242254

243255
## ⚙️ Development Workflow and Contributing
244256

README.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extensi
9797

9898
## 🤖 Compatibility with Meilisearch
9999

100-
This package only guarantees the compatibility with the [version v0.24.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.24.0).
100+
This package only guarantees the compatibility with the [version v0.25.0 of MeiliSearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.25.0).
101101

102102
## ⚙️ Development Workflow and Contributing
103103

meilisearch-test-macro/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "meilisearch-test-macro"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
proc-macro = true
8+
9+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
10+
11+
[dependencies]
12+
proc-macro2 = "1.0.0"
13+
quote = "1.0.0"
14+
syn = { version = "1.0.0", features = ["clone-impls", "full", "parsing", "printing", "proc-macro"], default-features = false }

meilisearch-test-macro/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Meilisearch test macro
2+
3+
This crate defines the `meilisearch_test` macro.
4+
5+
Since the code is a little bit harsh to read, here is a complete explanation of how to use it.
6+
The macro aims to ease the writing of tests by:
7+
1. Reducing the amount of code you need to write and maintain for each test.
8+
2. Ensuring All your indexes as a unique name so they can all run in parallel.
9+
3. Ensuring you never forget to delete your index if you need one.
10+
11+
12+
Before explaining its usage, we're going to see a simple test *before* this macro:
13+
```rust
14+
#[async_test]
15+
async fn test_get_tasks() -> Result<(), Error> {
16+
let client = Client::new("http://localhost:7700", "masterKey");
17+
18+
let index = client
19+
.create_index("test_get_tasks", None)
20+
.await?
21+
.wait_for_completion(&client, None, None)
22+
.await?
23+
.try_make_index(&client)
24+
.unwrap();
25+
26+
let tasks = index.get_tasks().await?;
27+
// The only task is the creation of the index
28+
assert_eq!(status.len(), 1);
29+
30+
index.delete()
31+
.await?
32+
.wait_for_completion(&client, None, None)
33+
.await?;
34+
Ok(())
35+
}
36+
```
37+
38+
I have multiple problems with this test:
39+
- `let client = Client::new("http://localhost:7700", "masterKey");`: This line is always the same in every test.
40+
And if you make a typo on the http addr or the master key, you'll have an error.
41+
- `let index = client.create_index("test_get_tasks", None)...`: Each test needs to have an unique name.
42+
This means we currently need to write the name of the test everywhere; it's not practical.
43+
- There are 11 lines dedicated to the creation and deletion of the index; this is once again something that'll never change
44+
whatever the test is. But, if you ever forget to delete the index at the end, you'll get in some trouble to re-run
45+
the tests.
46+
47+
-------
48+
49+
With this macro, all these problems are solved. See a rewrite of this test:
50+
```rust
51+
#[meilisearch_test]
52+
async fn test_get_tasks(index: Index, client: Client) -> Result<(), Error> {
53+
let tasks = index.get_tasks().await?;
54+
// The only task is the creation of the index
55+
assert_eq!(status.len(), 1);
56+
}
57+
```
58+
59+
So now you're probably seeing what happened. By using an index and a client in the parameter of
60+
the test, the macro automatically did the same thing we've seen before.
61+
There are a few rules, though:
62+
1. The macro only handles three types of arguments:
63+
- `String`: It returns the name of the test.
64+
- `Client`: It creates a client like that: `Client::new("http://localhost:7700", "masterKey")`.
65+
- `Index`: It creates and deletes an index, as we've seen before.
66+
2. You only get what you asked for. That means if you don't ask for an index, no index will be created in meilisearch.
67+
So, if you are testing the creation of indexes, you can ask for a `Client` and a `String` and then create it yourself.
68+
The index won't be present in meilisearch.
69+
3. You can put your parameters in the order you want it won't change anything.
70+
4. Everything you use **must** be in scope directly. If you're using an `Index`, you must write `Index` in the parameters,
71+
not `meilisearch_rust::Index` or `crate::Index`.
72+
5. And I think that's all, use and abuse it 🎉

0 commit comments

Comments
 (0)