at master 4.1 kB view raw
1{ 2 system ? builtins.currentSystem, 3 config ? { }, 4 pkgs ? import ../../.. { inherit system config; }, 5}: 6 7with pkgs.lib; 8 9let 10 baseModule = 11 { config, ... }: 12 { 13 imports = [ 14 { 15 options.test-helpers = { 16 rclone = mkOption { type = types.str; }; 17 upload-sample = mkOption { type = types.str; }; 18 check-sample = mkOption { type = types.str; }; 19 init = mkOption { 20 type = types.str; 21 default = ""; 22 }; 23 extraTests = mkOption { 24 type = types.either types.str (types.functionTo types.str); 25 default = ""; 26 }; 27 }; 28 options.adminuser = mkOption { type = types.str; }; 29 options.adminpass = mkOption { type = types.str; }; 30 } 31 ]; 32 33 adminuser = "root"; 34 adminpass = "hunter2"; 35 36 test-helpers.rclone = "${pkgs.writeShellScript "rclone" '' 37 set -euo pipefail 38 export PATH="${pkgs.rclone}/bin:$PATH" 39 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav 40 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/dav/files/${config.adminuser}" 41 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud" 42 export RCLONE_CONFIG_NEXTCLOUD_USER="${config.adminuser}" 43 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(rclone obscure ${config.adminpass})" 44 exec "$@" 45 ''}"; 46 test-helpers.upload-sample = "${pkgs.writeShellScript "rclone-upload" '' 47 <<<'hi' rclone rcat nextcloud:test-shared-file 48 ''}"; 49 test-helpers.check-sample = "${pkgs.writeShellScript "check-sample" '' 50 set -e 51 diff <(echo 'hi') <(rclone cat nextcloud:test-shared-file) 52 ''}"; 53 54 nodes = { 55 client = { ... }: { }; 56 nextcloud = 57 { lib, ... }: 58 { 59 networking.firewall.allowedTCPPorts = [ 80 ]; 60 services.nextcloud = { 61 enable = true; 62 hostName = "nextcloud"; 63 https = false; 64 database.createLocally = lib.mkDefault true; 65 config = { 66 adminpassFile = "${pkgs.writeText "adminpass" config.adminpass}"; # Don't try this at home! 67 }; 68 }; 69 }; 70 }; 71 72 testScript = 73 args@{ nodes, ... }: 74 let 75 inherit (config) test-helpers; 76 in 77 mkBefore '' 78 nextcloud.start() 79 client.start() 80 nextcloud.wait_for_unit("multi-user.target") 81 82 ${test-helpers.init} 83 84 with subtest("Ensure nextcloud-occ is working"): 85 nextcloud.succeed("nextcloud-occ status") 86 nextcloud.succeed("curl -sSf http://nextcloud/login") 87 88 with subtest("Upload/Download test"): 89 nextcloud.succeed( 90 "${test-helpers.rclone} ${test-helpers.upload-sample}" 91 ) 92 client.wait_for_unit("multi-user.target") 93 client.succeed( 94 "${test-helpers.rclone} ${test-helpers.check-sample}" 95 ) 96 97 ${ 98 if pkgs.lib.isFunction test-helpers.extraTests then 99 test-helpers.extraTests args 100 else 101 test-helpers.extraTests 102 } 103 ''; 104 }; 105 106 genTests = 107 version: 108 let 109 testBase.imports = [ 110 baseModule 111 { 112 nodes.nextcloud = 113 { pkgs, ... }: 114 { 115 services.nextcloud.package = pkgs.${"nextcloud${toString version}"}; 116 }; 117 } 118 ]; 119 120 callNextcloudTest = 121 path: 122 let 123 name = "${removeSuffix ".nix" (baseNameOf path)}${toString version}"; 124 in 125 nameValuePair name ( 126 import path { 127 inherit system pkgs testBase; 128 name = "nextcloud-${name}"; 129 } 130 ); 131 in 132 map callNextcloudTest [ 133 ./basic.nix 134 ./with-declarative-redis-and-secrets.nix 135 ./with-mysql-and-memcached.nix 136 ./with-postgresql-and-redis.nix 137 ./with-objectstore.nix 138 ]; 139in 140listToAttrs ( 141 concatMap genTests [ 142 31 143 ] 144)