blob: b30f50c115b47f53900a803047dfc4a67a7ec441 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
{ lib, pkgs, ... }:
let
mkTestZim =
name:
pkgs.runCommandLocal "${name}.zim"
{
nativeBuildInputs = [ pkgs.zim-tools ];
}
''
${lib.getExe' pkgs.zim-tools "zimwriterfs"} \
--name "${name}" \
--title 'NixOS kiwix-serve Test' \
--description 'NixOS test of kiwix-serve' \
--creator Nixpkgs \
--publisher Nixpkgs \
--language eng \
--welcome index.html \
--illustration icon.png \
${./html} \
$out
'';
# Test files must have different names or kiwix-serve will only serve one of them
testZimStore = mkTestZim "test-store";
testZimOutside = mkTestZim "test-outside";
in
{
name = "kiwix-serve";
meta.maintainers = with lib.maintainers; [ MysteryBlokHed ];
nodes = {
machine = {
systemd.services.copy-zim-file = {
description = "Copy test ZIM file to host system to test paths outside of store";
wantedBy = [ "multi-user.target" ];
before = [ "kiwix-serve.service" ];
requiredBy = [ "kiwix-serve.service" ];
serviceConfig = {
Type = "oneshot";
};
script = ''
mkdir -p /var/lib/kiwix-serve
cp ${testZimOutside} /var/lib/kiwix-serve/test-outside.zim
'';
};
services.kiwix-serve = {
enable = true;
port = 8080;
library = {
test-store = testZimStore;
test-outside = "/var/lib/kiwix-serve/test-outside.zim";
};
};
};
};
testScript = ''
machine.wait_for_unit("kiwix-serve.service")
machine.wait_for_open_port(8080)
machine.wait_until_succeeds("curl --fail --silent --head http://localhost:8080")
# ZIM file in store
test_content = machine.succeed("curl --fail --silent --location http://localhost:8080/content/test-store")
print(test_content)
assert "NixOS test of kiwix-serve" in test_content, "kiwix-serve did not provide the expected page for the store ZIM file"
# ZIM file outside of store
test_content = machine.succeed("curl --fail --silent --location http://localhost:8080/content/test-outside")
print(test_content)
assert "NixOS test of kiwix-serve" in test_content, "kiwix-serve did not provide the expected page for the out-of-store ZIM file"
'';
}
|