at 22.05-pre 2.0 kB view raw
1import ./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.runCommand "movies.json" {} '' 9 sed -n '1,5p;$p' ${pkgs.meilisearch.src}/datasets/movies/movies.json > $out 10 ''; 11 in { 12 name = "meilisearch"; 13 meta.maintainers = with lib.maintainers; [ Br1ght0ne ]; 14 15 machine = { ... }: { 16 environment.systemPackages = with pkgs; [ curl jq ]; 17 services.meilisearch = { 18 enable = true; 19 inherit listenAddress listenPort; 20 }; 21 }; 22 23 testScript = '' 24 import json 25 26 start_all() 27 28 machine.wait_for_unit("meilisearch") 29 machine.wait_for_open_port("7700") 30 31 with subtest("check version"): 32 version = json.loads(machine.succeed("curl ${apiUrl}/version")) 33 assert version["pkgVersion"] == "${pkgs.meilisearch.version}" 34 35 with subtest("create index"): 36 machine.succeed( 37 "curl -XPOST ${apiUrl}/indexes --data @${indexJSON}" 38 ) 39 indexes = json.loads(machine.succeed("curl ${apiUrl}/indexes")) 40 assert len(indexes) == 1, "index wasn't created" 41 42 with subtest("add documents"): 43 response = json.loads( 44 machine.succeed( 45 "curl -XPOST ${apiUrl}/indexes/${uid}/documents --data @${moviesJSON}" 46 ) 47 ) 48 update_id = response["updateId"] 49 machine.wait_until_succeeds( 50 f"curl ${apiUrl}/indexes/${uid}/updates/{update_id} | jq -e '.status == \"processed\"'" 51 ) 52 53 with subtest("search"): 54 response = json.loads( 55 machine.succeed("curl ${apiUrl}/indexes/movies/search?q=hero") 56 ) 57 print(response) 58 assert len(response["hits"]) >= 1, "no results found" 59 ''; 60 })