at 25.11-pre 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 } // testConfig.calibreConfig or { }; 83 librariesInitScript = path: '' 84 ${nodeName}.execute("touch /tmp/test.epub") 85 ${nodeName}.execute("zip -r /tmp/test.zip /tmp/test.epub") 86 ${nodeName}.execute("mkdir -p ${path}") 87 ${nodeName}.execute("calibredb add -d --with-library ${path} /tmp/test.zip") 88 ''; 89 in 90 { 91 name = "calibre-server-${test}"; 92 93 nodes.${nodeName} = mkMerge [ 94 { 95 environment.systemPackages = [ pkgs.zip ]; 96 services.calibre-server = calibreConfig; 97 } 98 testConfig.calibreProvider or { } 99 ]; 100 101 testScript = '' 102 ${nodeName}.start() 103 ${concatStringsSep "\n" (map librariesInitScript calibreConfig.libraries)} 104 ${concatStringsSep "\n" ( 105 map ( 106 line: 107 if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")") then 108 line 109 else 110 "${nodeName}.${line}" 111 ) (splitString "\n" (removeSuffix "\n" testConfig.calibreScript)) 112 )} 113 ${nodeName}.shutdown() 114 ''; 115 116 meta = with maintainers; { 117 maintainers = [ gaelreyrol ]; 118 }; 119 } 120 )) 121) tests