Skip to content

Commit b3a882b

Browse files
bors[bot]washbin
andauthored
Merge #353
353: Rename MEILISEARCH_HOST to MEILISEARCH_URL r=bidoubiwa a=washbin # Pull Request ## Related issue Fixes #352 ## What does this PR do? - rename env variables ## 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? Co-authored-by: washbin <[email protected]> Co-authored-by: Ashbin Wosti <[email protected]>
2 parents 18c835f + 1e161fd commit b3a882b

File tree

13 files changed

+293
-304
lines changed

13 files changed

+293
-304
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct Movie {
111111

112112
fn main() { block_on(async move {
113113
// Create a client (without sending any request so that can't fail)
114-
let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
114+
let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
115115

116116
// An index is where the documents are stored.
117117
let movies = client.index("movies");

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
stdin_open: true
1313
working_dir: /home/package
1414
environment:
15-
- MEILISEARCH_HOST=http://meilisearch:7700
15+
- MEILISEARCH_URL=http://meilisearch:7700
1616
- CARGO_HOME=/vendor/cargo
1717
depends_on:
1818
- meilisearch

meilisearch-test-macro/README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ This crate defines the `meilisearch_test` macro.
44

55
Since the code is a little bit harsh to read, here is a complete explanation of how to use it.
66
The macro aims to ease the writing of tests by:
7+
78
1. Reducing the amount of code you need to write and maintain for each test.
89
2. Ensuring All your indexes as a unique name so they can all run in parallel.
910
3. Ensuring you never forget to delete your index if you need one.
1011

12+
Before explaining its usage, we're going to see a simple test _before_ this macro:
1113

12-
Before explaining its usage, we're going to see a simple test *before* this macro:
1314
```rust
1415
#[async_test]
1516
async fn test_get_tasks() -> Result<(), Error> {
16-
let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
17+
let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
1718

1819
let index = client
1920
.create_index("test_get_tasks", None)
@@ -36,17 +37,19 @@ async fn test_get_tasks() -> Result<(), Error> {
3637
```
3738

3839
I have multiple problems with this test:
39-
- `let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);`: This line is always the same in every test.
40+
41+
- `let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);`: This line is always the same in every test.
4042
And if you make a typo on the http addr or the master key, you'll have an error.
4143
- `let index = client.create_index("test_get_tasks", None)...`: Each test needs to have an unique name.
4244
This means we currently need to write the name of the test everywhere; it's not practical.
4345
- There are 11 lines dedicated to the creation and deletion of the index; this is once again something that'll never change
4446
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
4547
the tests.
4648

47-
-------
49+
---
4850

4951
With this macro, all these problems are solved. See a rewrite of this test:
52+
5053
```rust
5154
#[meilisearch_test]
5255
async fn test_get_tasks(index: Index, client: Client) -> Result<(), Error> {
@@ -59,14 +62,17 @@ async fn test_get_tasks(index: Index, client: Client) -> Result<(), Error> {
5962
So now you're probably seeing what happened. By using an index and a client in the parameter of
6063
the test, the macro automatically did the same thing we've seen before.
6164
There are a few rules, though:
65+
6266
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.
67+
68+
- `String`: It returns the name of the test.
69+
- `Client`: It creates a client like that: `Client::new("http://localhost:7700", "masterKey")`.
70+
- `Index`: It creates and deletes an index, as we've seen before.
71+
6672
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.
73+
So, if you are testing the creation of indexes, you can ask for a `Client` and a `String` and then create it yourself.
74+
The index won't be present in meilisearch.
6975
3. You can put your parameters in the order you want it won't change anything.
7076
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`.
77+
not `meilisearch_rust::Index` or `crate::Index`.
7278
5. And I think that's all, use and abuse it 🎉

meilisearch-test-macro/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ pub fn meilisearch_test(params: TokenStream, input: TokenStream) -> TokenStream
8383
// First we need to check if a client will be used and create it if it’s the case
8484
if use_client {
8585
outer_block.push(parse_quote!(
86-
let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
86+
let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
8787
));
8888
outer_block.push(parse_quote!(
8989
let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
9090
));
9191
outer_block.push(parse_quote!(
92-
let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
92+
let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
9393
));
9494
}
9595

0 commit comments

Comments
 (0)