1import ./make-test-python.nix (
2 { pkgs, lib, ... }:
3 let
4 listenAddress = "127.0.0.1";
5 listenPort = 7700;
6 apiUrl = "http://${listenAddress}:${toString listenPort}";
7 uid = "movies";
8 indexJSON = pkgs.writeText "index.json" (builtins.toJSON { inherit uid; });
9 moviesJSON = pkgs.fetchurl {
10 url = "https://github.com/meilisearch/meilisearch/raw/v0.23.1/datasets/movies/movies.json";
11 sha256 = "1r3srld63dpmg9yrmysm6xl175661j5cspi93mk5q2wf8xwn50c5";
12 };
13 in
14 {
15 name = "meilisearch";
16 meta.maintainers = with lib.maintainers; [ Br1ght0ne ];
17
18 nodes.machine =
19 { ... }:
20 {
21 environment.systemPackages = with pkgs; [
22 curl
23 jq
24 ];
25 services.meilisearch = {
26 enable = true;
27 inherit listenAddress listenPort;
28 };
29 };
30
31 testScript = ''
32 import json
33
34 start_all()
35
36 machine.wait_for_unit("meilisearch")
37 machine.wait_for_open_port(7700)
38
39 with subtest("check version"):
40 version = json.loads(machine.succeed("curl ${apiUrl}/version"))
41 assert version["pkgVersion"] == "${pkgs.meilisearch.version}"
42
43 with subtest("create index"):
44 machine.succeed(
45 "curl -X POST -H 'Content-Type: application/json' ${apiUrl}/indexes --data @${indexJSON}"
46 )
47 indexes = json.loads(machine.succeed("curl ${apiUrl}/indexes"))
48 assert indexes["total"] == 1, "index wasn't created"
49
50 with subtest("add documents"):
51 response = json.loads(
52 machine.succeed(
53 "curl -X POST -H 'Content-Type: application/json' ${apiUrl}/indexes/${uid}/documents --data-binary @${moviesJSON}"
54 )
55 )
56 task_uid = response["taskUid"]
57 machine.wait_until_succeeds(
58 f"curl ${apiUrl}/tasks/{task_uid} | jq -e '.status == \"succeeded\"'"
59 )
60
61 with subtest("search"):
62 response = json.loads(
63 machine.succeed("curl ${apiUrl}/indexes/movies/search?q=hero")
64 )
65 print(response)
66 assert len(response["hits"]) >= 1, "no results found"
67 '';
68 }
69)