2020-04-07 12:00:43 +03:00
|
|
|
import ./make-test-python.nix ({ pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
listenAddress = "127.0.0.1";
|
|
|
|
listenPort = 7700;
|
|
|
|
apiUrl = "http://${listenAddress}:${toString listenPort}";
|
|
|
|
uid = "movies";
|
|
|
|
indexJSON = pkgs.writeText "index.json" (builtins.toJSON { inherit uid; });
|
2022-05-27 14:59:04 +03:00
|
|
|
moviesJSON = pkgs.fetchurl {
|
|
|
|
url = "https://github.com/meilisearch/meilisearch/raw/v0.23.1/datasets/movies/movies.json";
|
|
|
|
sha256 = "1r3srld63dpmg9yrmysm6xl175661j5cspi93mk5q2wf8xwn50c5";
|
|
|
|
};
|
2020-04-07 12:00:43 +03:00
|
|
|
in {
|
|
|
|
name = "meilisearch";
|
2021-09-22 12:18:05 +03:00
|
|
|
meta.maintainers = with lib.maintainers; [ Br1ght0ne ];
|
2020-04-07 12:00:43 +03:00
|
|
|
|
2022-03-21 02:15:30 +03:00
|
|
|
nodes.machine = { ... }: {
|
2020-04-07 12:00:43 +03:00
|
|
|
environment.systemPackages = with pkgs; [ curl jq ];
|
|
|
|
services.meilisearch = {
|
|
|
|
enable = true;
|
|
|
|
inherit listenAddress listenPort;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
import json
|
|
|
|
|
|
|
|
start_all()
|
|
|
|
|
|
|
|
machine.wait_for_unit("meilisearch")
|
2022-06-11 15:22:53 +03:00
|
|
|
machine.wait_for_open_port(7700)
|
2020-04-07 12:00:43 +03:00
|
|
|
|
|
|
|
with subtest("check version"):
|
|
|
|
version = json.loads(machine.succeed("curl ${apiUrl}/version"))
|
|
|
|
assert version["pkgVersion"] == "${pkgs.meilisearch.version}"
|
|
|
|
|
|
|
|
with subtest("create index"):
|
|
|
|
machine.succeed(
|
2022-08-24 21:50:06 +03:00
|
|
|
"curl -X POST -H 'Content-Type: application/json' ${apiUrl}/indexes --data @${indexJSON}"
|
2020-04-07 12:00:43 +03:00
|
|
|
)
|
|
|
|
indexes = json.loads(machine.succeed("curl ${apiUrl}/indexes"))
|
2022-08-24 21:50:06 +03:00
|
|
|
assert indexes["total"] == 1, "index wasn't created"
|
2020-04-07 12:00:43 +03:00
|
|
|
|
|
|
|
with subtest("add documents"):
|
|
|
|
response = json.loads(
|
|
|
|
machine.succeed(
|
2022-08-24 21:50:06 +03:00
|
|
|
"curl -X POST -H 'Content-Type: application/json' ${apiUrl}/indexes/${uid}/documents --data-binary @${moviesJSON}"
|
2020-04-07 12:00:43 +03:00
|
|
|
)
|
|
|
|
)
|
2022-08-24 21:50:06 +03:00
|
|
|
task_uid = response["taskUid"]
|
2020-04-07 12:00:43 +03:00
|
|
|
machine.wait_until_succeeds(
|
2022-08-24 21:50:06 +03:00
|
|
|
f"curl ${apiUrl}/tasks/{task_uid} | jq -e '.status == \"succeeded\"'"
|
2020-04-07 12:00:43 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
with subtest("search"):
|
|
|
|
response = json.loads(
|
|
|
|
machine.succeed("curl ${apiUrl}/indexes/movies/search?q=hero")
|
|
|
|
)
|
|
|
|
print(response)
|
|
|
|
assert len(response["hits"]) >= 1, "no results found"
|
|
|
|
'';
|
|
|
|
})
|