Merge pull request #308829 from r-ryantm/auto-update/qlog
[NixPkgs.git] / nixos / tests / nextcloud / with-postgresql-and-redis.nix
blob06afc589403ddab50976b6d52ac69d40d5c9e802
1 args@{ pkgs, nextcloudVersion ? 22, ... }:
3 (import ../make-test-python.nix ({ pkgs, ...}: let
4   adminpass = "hunter2";
5   adminuser = "custom-admin-username";
6 in {
7   name = "nextcloud-with-postgresql-and-redis";
8   meta = with pkgs.lib.maintainers; {
9     maintainers = [ eqyiel ];
10   };
12   nodes = {
13     # The only thing the client needs to do is download a file.
14     client = { ... }: {};
16     nextcloud = { config, pkgs, lib, ... }: {
17       networking.firewall.allowedTCPPorts = [ 80 ];
19       services.nextcloud = {
20         enable = true;
21         hostName = "nextcloud";
22         package = pkgs.${"nextcloud" + (toString nextcloudVersion)};
23         caching = {
24           apcu = false;
25           redis = true;
26           memcached = false;
27         };
28         database.createLocally = true;
29         config = {
30           dbtype = "pgsql";
31           inherit adminuser;
32           adminpassFile = toString (pkgs.writeText "admin-pass-file" ''
33             ${adminpass}
34           '');
35         };
36         notify_push = {
37           enable = true;
38           logLevel = "debug";
39         };
40         extraAppsEnable = true;
41         extraApps = {
42           inherit (pkgs."nextcloud${lib.versions.major config.services.nextcloud.package.version}Packages".apps) notify_push notes;
43         };
44         settings.trusted_proxies = [ "::1" ];
45       };
47       services.redis.servers."nextcloud".enable = true;
48       services.redis.servers."nextcloud".port = 6379;
49     };
50   };
52   testScript = let
53     configureRedis = pkgs.writeScript "configure-redis" ''
54       #!${pkgs.runtimeShell}
55       nextcloud-occ config:system:set redis 'host' --value 'localhost' --type string
56       nextcloud-occ config:system:set redis 'port' --value 6379 --type integer
57       nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\Redis' --type string
58       nextcloud-occ config:system:set memcache.locking --value '\OC\Memcache\Redis' --type string
59     '';
60     withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
61       #!${pkgs.runtimeShell}
62       export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
63       export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/dav/files/${adminuser}"
64       export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
65       export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
66       export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})"
67       "''${@}"
68     '';
69     copySharedFile = pkgs.writeScript "copy-shared-file" ''
70       #!${pkgs.runtimeShell}
71       echo 'hi' | ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
72     '';
74     diffSharedFile = pkgs.writeScript "diff-shared-file" ''
75       #!${pkgs.runtimeShell}
76       diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file)
77     '';
78   in ''
79     start_all()
80     nextcloud.wait_for_unit("multi-user.target")
81     nextcloud.succeed("${configureRedis}")
82     nextcloud.succeed("curl -sSf http://nextcloud/login")
83     nextcloud.succeed(
84         "${withRcloneEnv} ${copySharedFile}"
85     )
86     client.wait_for_unit("multi-user.target")
87     client.execute("${pkgs.lib.getExe pkgs.nextcloud-notify_push.passthru.test_client} http://nextcloud ${adminuser} ${adminpass} >&2 &")
88     client.succeed(
89         "${withRcloneEnv} ${diffSharedFile}"
90     )
91     nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${adminuser}\"")
93     # redis cache should not be empty
94     nextcloud.fail('test "[]" = "$(redis-cli --json KEYS "*")"')
96     nextcloud.fail("curl -f http://nextcloud/nix-apps/notes/lib/AppInfo/Application.php")
97   '';
98 })) args