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