Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume

## Development Workflow

### Setup <!-- omit in TOC -->

You can set up your local environment natively or using `docker`, check out the [`docker-compose.yml`](/docker-compose.yml).

Example of running all the checks with docker:
```bash
docker-compose run --rm package bash -c "./gradlew build && ./gradlew test IntegrationTest"
```

To install dependencies:

```bash
./gradlew build
```


Comment on lines +43 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

### Tests <!-- omit in TOC -->

Integration and unit tests will be run in your PR to check everything is OK. Each PR should pass all the tests to be accepted.
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3.8"

services:
package:
image: gradle:7.4.2-jdk8
tty: true
stdin_open: true
working_dir: /home/package
environment:
- MEILISEARCH_HOST=http://meilisearch:7700
depends_on:
- meilisearch
links:
- meilisearch
volumes:
- ./:/home/package

meilisearch:
image: getmeili/meilisearch:latest
ports:
- "7700"
environment:
- MEILI_MASTER_KEY=masterKey
- MEILI_NO_ANALYTICS=true
26 changes: 13 additions & 13 deletions src/test/java/com/meilisearch/integration/TenantTokenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public void testGenerateTenantTokenWithOnlySearchRules() throws Exception {
Index index = createEmptyIndex(indexUid);
Key key = getPrivateKey();

Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));

Map<String, Object> rules = new HashMap<String, Object>();
rules.put("*", new HashMap<String, Object>());

String jwtToken = privateClient.generateTenantToken(rules);

Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));

assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
}
Expand All @@ -64,14 +64,14 @@ public void testGenerateTenantTokenOnOneIndex() throws Exception {
Index index = createEmptyIndex(indexUid);
Key key = getPrivateKey();

Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));

Map<String, Object> rules = new HashMap<String, Object>();
rules.put(indexUid, new HashMap<String, Object>());

String jwtToken = privateClient.generateTenantToken(rules);

Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));

assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
}
Expand All @@ -82,7 +82,7 @@ public void testGenerateTenantTokenWithFilter() throws Exception {
Key key = getPrivateKey();
String indexUid = "GenerateTokenwithFilter";

Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));

Map<String, Object> filters = new HashMap<String, Object>();
filters.put("filter", "id > 1");
Expand All @@ -91,7 +91,7 @@ public void testGenerateTenantTokenWithFilter() throws Exception {

String jwtToken = privateClient.generateTenantToken(rules);

Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));

Index index = client.index(indexUid);
TestData<Movie> testData = this.getTestData(MOVIES_INDEX, Movie.class);
Expand All @@ -116,7 +116,7 @@ public void testGenerateTenantTokenWithExpiresAt() throws Exception {
Index index = createEmptyIndex(indexUid);
Key key = getPrivateKey();

Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));

Map<String, Object> rules = new HashMap<String, Object>();
rules.put("*", new HashMap<String, Object>());
Expand All @@ -129,7 +129,7 @@ public void testGenerateTenantTokenWithExpiresAt() throws Exception {

String jwtToken = privateClient.generateTenantToken(rules, options);

Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));

assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
}
Expand All @@ -149,7 +149,7 @@ public void testGenerateTenantTokenWithApiKey() throws Exception {

String jwtToken = client.generateTenantToken(rules, options);

Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));

assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
}
Expand All @@ -173,7 +173,7 @@ public void testGenerateTenantTokenWithAllOptions() throws Exception {

String jwtToken = client.generateTenantToken(rules, options);

Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));

assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
}
Expand All @@ -184,7 +184,7 @@ public void testGenerateTenantTokenWithNoSearchRules() throws Exception {
String indexUid = "GenerateTokenWithNoSearchRules";
Key key = getPrivateKey();

Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));

assertThrows(MeiliSearchException.class, () -> privateClient.generateTenantToken(null));
}
Expand All @@ -195,7 +195,7 @@ public void testGenerateTenantTokenWithBadExpiresAt() throws Exception {
String indexUid = "GenerateTenantTokenWithBadExpiresAt";
Key key = getPrivateKey();

Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));

Map<String, Object> rules = new HashMap<String, Object>();
rules.put("*", new HashMap<String, Object>());
Expand All @@ -217,7 +217,7 @@ public void testGenerateTenantTokenWithBadExpiresAt() throws Exception {
public void testGenerateTenantTokenWithEmptyApiKey() throws Exception {
String indexUid = "GenerateTenantTokenWithEmptyApiKey";

Client privateClient = new Client(new Config("http://localhost:7700"));
Client privateClient = new Client(new Config(getMeilisearchHost()));

Map<String, Object> rules = new HashMap<String, Object>();
rules.put("*", new HashMap<String, Object>());
Expand Down
14 changes: 11 additions & 3 deletions src/test/java/com/meilisearch/integration/classes/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ public AbstractIT() {
}

public void setUp() {
if (client == null) client = new Client(new Config("http://localhost:7700", "masterKey"));
if (client == null) client = new Client(new Config(getMeilisearchHost(), "masterKey"));
}

public static void cleanup() {
deleteAllIndexes();
}

public static String getMeilisearchHost() {
String meilisearchHost = System.getenv("MEILISEARCH_HOST");
if (meilisearchHost != null) {
return meilisearchHost;
}
return "http://localhost:7700";
}

public Index createEmptyIndex(String indexUid) throws Exception {
Task task = client.createIndex(indexUid);
client.waitForTask(task.getUid());
Expand Down Expand Up @@ -84,7 +92,7 @@ public Key getPrivateKey() throws Exception {

public static void deleteAllIndexes() {
try {
Client ms = new Client(new Config("http://localhost:7700", "masterKey"));
Client ms = new Client(new Config(getMeilisearchHost(), "masterKey"));
Index[] indexes = ms.getIndexList();
for (Index index : indexes) {
ms.deleteIndex(index.getUid());
Expand All @@ -96,7 +104,7 @@ public static void deleteAllIndexes() {

public static void deleteAllKeys() {
try {
Client ms = new Client(new Config("http://localhost:7700", "masterKey"));
Client ms = new Client(new Config(getMeilisearchHost(), "masterKey"));
Key[] keys = ms.getKeys();
for (Key key : keys) {
if ((key.getDescription() == null) || (key.getDescription().contains("test"))) {
Expand Down