diff options
author | Oleksii Filonenko <brightone@protonmail.com> | 2020-04-07 12:00:43 +0300 |
---|---|---|
committer | Raphael Megzari <raphael@megzari.com> | 2021-09-20 16:12:29 +0900 |
commit | be72fadd548864f60fbb69dcb3d3b389ec79979c (patch) | |
tree | 3af3af3d6997a42c327fc1ed459c3f973901d2fb /nixos/tests/meilisearch.nix | |
parent | 811fe35a665fa47cf88c97e9e6aa395526d3a9b6 (diff) |
nixosTests.meilisearch: init
(cherry picked from commit 4cc2d55f6ac2440843ef3387909dbc703f65397d)
Diffstat (limited to 'nixos/tests/meilisearch.nix')
-rw-r--r-- | nixos/tests/meilisearch.nix | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/nixos/tests/meilisearch.nix b/nixos/tests/meilisearch.nix new file mode 100644 index 0000000000000..ef5781458ffdb --- /dev/null +++ b/nixos/tests/meilisearch.nix @@ -0,0 +1,60 @@ +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; }); + moviesJSON = pkgs.runCommand "movies.json" {} '' + sed -n '1,5p;$p' ${pkgs.meilisearch.src}/datasets/movies/movies.json > $out + ''; + in { + name = "meilisearch"; + meta.maintainers = with lib.maintainers; [ filalex77 ]; + + machine = { ... }: { + environment.systemPackages = with pkgs; [ curl jq ]; + services.meilisearch = { + enable = true; + inherit listenAddress listenPort; + }; + }; + + testScript = '' + import json + + start_all() + + machine.wait_for_unit("meilisearch") + machine.wait_for_open_port("7700") + + with subtest("check version"): + version = json.loads(machine.succeed("curl ${apiUrl}/version")) + assert version["pkgVersion"] == "${pkgs.meilisearch.version}" + + with subtest("create index"): + machine.succeed( + "curl -XPOST ${apiUrl}/indexes --data @${indexJSON}" + ) + indexes = json.loads(machine.succeed("curl ${apiUrl}/indexes")) + assert len(indexes) == 1, "index wasn't created" + + with subtest("add documents"): + response = json.loads( + machine.succeed( + "curl -XPOST ${apiUrl}/indexes/${uid}/documents --data @${moviesJSON}" + ) + ) + update_id = response["updateId"] + machine.wait_until_succeeds( + f"curl ${apiUrl}/indexes/${uid}/updates/{update_id} | jq -e '.status == \"processed\"'" + ) + + 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" + ''; + }) |