vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / calibre-server.nix
blob4b1753aaa7049f4b865a4535a226b90680548590
1 { system ? builtins.currentSystem
2 , config ? { }
3 , pkgs ? import ../.. { inherit system config; }
4 }:
6 let
7   inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
8   inherit (pkgs.lib) concatStringsSep maintainers mapAttrs mkMerge
9     removeSuffix splitString;
11   tests = {
12     default = {
13       calibreConfig = {};
14       calibreScript = ''
15         wait_for_unit("calibre-server.service")
16       '';
17     };
18     customLibrary = {
19       calibreConfig = {
20         libraries = [ "/var/lib/calibre-data" ];
21       };
22       calibreScript = ''
23         succeed("ls -la /var/lib/calibre-data")
24         wait_for_unit("calibre-server.service")
25       '';
26     };
27     multipleLibraries = {
28       calibreConfig = {
29         libraries = [ "/var/lib/calibre-data" "/var/lib/calibre-server" ];
30       };
31       calibreScript = ''
32         succeed("ls -la /var/lib/calibre-data")
33         succeed("ls -la /var/lib/calibre-server")
34         wait_for_unit("calibre-server.service")
35       '';
36     };
37     hostAndPort = {
38       calibreConfig = {
39         host = "127.0.0.1";
40         port = 8888;
41       };
42       calibreScript = ''
43         wait_for_unit("calibre-server.service")
44         wait_for_open_port(8888)
45         succeed("curl --fail http://127.0.0.1:8888")
46       '';
47     };
48     basicAuth = {
49       calibreConfig = {
50         host = "127.0.0.1";
51         port = 8888;
52         auth = {
53           enable = true;
54           mode = "basic";
55         };
56       };
57       calibreScript = ''
58         wait_for_unit("calibre-server.service")
59         wait_for_open_port(8888)
60         fail("curl --fail http://127.0.0.1:8888")
61       '';
62     };
63   };
65 mapAttrs
66   (test: testConfig: (makeTest (
67     let
68       nodeName = testConfig.nodeName or test;
69       calibreConfig = {
70         enable = true;
71         libraries = [ "/var/lib/calibre-server" ];
72       } // testConfig.calibreConfig or {};
73       librariesInitScript = path: ''
74         ${nodeName}.execute("touch /tmp/test.epub")
75         ${nodeName}.execute("zip -r /tmp/test.zip /tmp/test.epub")
76         ${nodeName}.execute("mkdir -p ${path}")
77         ${nodeName}.execute("calibredb add -d --with-library ${path} /tmp/test.zip")
78       '';
79     in
80     {
81       name = "calibre-server-${test}";
83       nodes.${nodeName} = mkMerge [{
84         environment.systemPackages = [ pkgs.zip ];
85         services.calibre-server = calibreConfig;
86       } testConfig.calibreProvider or { }];
88       testScript = ''
89         ${nodeName}.start()
90         ${concatStringsSep "\n" (map librariesInitScript calibreConfig.libraries)}
91         ${concatStringsSep "\n" (map (line:
92           if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")")
93           then line
94           else "${nodeName}.${line}"
95         ) (splitString "\n" (removeSuffix "\n" testConfig.calibreScript)))}
96         ${nodeName}.shutdown()
97       '';
99       meta = with maintainers; {
100         maintainers = [ gaelreyrol ];
101       };
102     }
103   )))
104   tests