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