Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nixos/doc: add calibre-server new options
- Loading branch information
1 parent
e35c69a
commit 9dd2f60
Showing
3 changed files
with
133 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,104 @@ | ||
import ./make-test-python.nix ( | ||
{ pkgs, lib, ... }: | ||
{ system ? builtins.currentSystem | ||
, config ? { } | ||
, pkgs ? import ../.. { inherit system config; } | ||
}: | ||
|
||
with lib; | ||
let | ||
inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest; | ||
inherit (pkgs.lib) concatStringsSep maintainers mapAttrs mkMerge | ||
removeSuffix splitString; | ||
|
||
let | ||
host = "127.0.0.1"; | ||
port = 8888; | ||
libraryPath = "/var/lib/calibre-data"; | ||
in | ||
{ | ||
name = "calibre-server"; | ||
|
||
nodes.machine = { config, pkgs, ... }: { | ||
services.calibre-server = { | ||
enable = true; | ||
inherit host port; | ||
libraries = [ libraryPath ]; | ||
tests = { | ||
default = { | ||
calibreConfig = {}; | ||
calibreScript = '' | ||
wait_for_unit("calibre-server.service") | ||
''; | ||
}; | ||
customLibrary = { | ||
calibreConfig = { | ||
libraries = [ "/var/lib/calibre-data" ]; | ||
}; | ||
calibreScript = '' | ||
succeed("ls -la /var/lib/calibre-data") | ||
wait_for_unit("calibre-server.service") | ||
''; | ||
}; | ||
multipleLibraries = { | ||
calibreConfig = { | ||
libraries = [ "/var/lib/calibre-data" "/var/lib/calibre-server" ]; | ||
}; | ||
calibreScript = '' | ||
succeed("ls -la /var/lib/calibre-data") | ||
succeed("ls -la /var/lib/calibre-server") | ||
wait_for_unit("calibre-server.service") | ||
''; | ||
}; | ||
hostAndPort = { | ||
calibreConfig = { | ||
host = "127.0.0.1"; | ||
port = 8888; | ||
}; | ||
calibreScript = '' | ||
wait_for_unit("calibre-server.service") | ||
wait_for_open_port(8888) | ||
succeed("curl --fail http://127.0.0.1:8888") | ||
''; | ||
}; | ||
basicAuth = { | ||
calibreConfig = { | ||
host = "127.0.0.1"; | ||
port = 8888; | ||
auth = { | ||
enable = true; | ||
mode = "basic"; | ||
}; | ||
}; | ||
calibreScript = '' | ||
wait_for_unit("calibre-server.service") | ||
wait_for_open_port(8888) | ||
fail("curl --fail http://127.0.0.1:8888") | ||
''; | ||
}; | ||
}; | ||
in | ||
mapAttrs | ||
(test: testConfig: (makeTest ( | ||
let | ||
nodeName = testConfig.nodeName or test; | ||
calibreConfig = { | ||
enable = true; | ||
libraries = [ "/var/lib/calibre-server" ]; | ||
} // testConfig.calibreConfig or {}; | ||
librariesInitScript = path: '' | ||
${nodeName}.execute("touch /tmp/test.epub") | ||
${nodeName}.execute("zip -r /tmp/test.zip /tmp/test.epub") | ||
${nodeName}.execute("mkdir -p ${path}") | ||
${nodeName}.execute("calibredb add -d --with-library ${path} /tmp/test.zip") | ||
''; | ||
in | ||
{ | ||
name = "calibre-server-${test}"; | ||
|
||
testScript = '' | ||
machine.start() | ||
machine.execute("mkdir -p ${libraryPath}") | ||
machine.execute("curl -o alice.epub https://www.gutenberg.org/ebooks/11.epub.noimages") | ||
machine.execute("calibredb add /tmp/alice.epub --with-library ${libraryPath}") | ||
machine.wait_for_unit("calibre-server.service") | ||
machine.wait_for_open_port(${toString port}) | ||
machine.succeed("curl --fail http://${host}:${toString port}") | ||
''; | ||
} | ||
) | ||
nodes.${nodeName} = mkMerge [{ | ||
environment.systemPackages = [ pkgs.zip ]; | ||
services.calibre-server = calibreConfig; | ||
} testConfig.calibreProvider or { }]; | ||
|
||
testScript = '' | ||
${nodeName}.start() | ||
${concatStringsSep "\n" (map librariesInitScript calibreConfig.libraries)} | ||
${concatStringsSep "\n" (map (line: | ||
if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")") | ||
then line | ||
else "${nodeName}.${line}" | ||
) (splitString "\n" (removeSuffix "\n" testConfig.calibreScript)))} | ||
${nodeName}.shutdown() | ||
''; | ||
|
||
meta = with maintainers; { | ||
maintainers = [ gaelreyrol ]; | ||
}; | ||
} | ||
))) | ||
tests |