jetbrains: 2024.1 -> 2024.2.7 (#351041)
[NixPkgs.git] / nixos / tests / mattermost.nix
blobe11201f05357da7ac7032f2a3c60656067df70b6
1 import ./make-test-python.nix ({ pkgs, lib, ... }:
2 let
3   host = "smoke.test";
4   port = "8065";
5   url = "http://${host}:${port}";
6   siteName = "NixOS Smoke Tests, Inc.";
8   makeMattermost = mattermostConfig:
9     { config, ... }: {
10       environment.systemPackages = [
11         pkgs.mattermost
12         pkgs.curl
13         pkgs.jq
14       ];
15       networking.hosts = {
16         "127.0.0.1" = [ host ];
17       };
18       services.mattermost = lib.recursiveUpdate {
19         enable = true;
20         inherit siteName;
21         listenAddress = "0.0.0.0:${port}";
22         siteUrl = url;
23         extraConfig = {
24           SupportSettings.AboutLink = "https://nixos.org";
25         };
26       } mattermostConfig;
27     };
30   name = "mattermost";
32   nodes = {
33     mutable = makeMattermost {
34       mutableConfig = true;
35       extraConfig.SupportSettings.HelpLink = "https://search.nixos.org";
36     };
37     mostlyMutable = makeMattermost {
38       mutableConfig = true;
39       preferNixConfig = true;
40       plugins = let
41         mattermostDemoPlugin = pkgs.fetchurl {
42           url = "https://github.com/mattermost/mattermost-plugin-demo/releases/download/v0.9.0/com.mattermost.demo-plugin-0.9.0.tar.gz";
43           sha256 = "1h4qi34gcxcx63z8wiqcf2aaywmvv8lys5g8gvsk13kkqhlmag25";
44         };
45       in [
46         mattermostDemoPlugin
47       ];
48     };
49     immutable = makeMattermost {
50       mutableConfig = false;
51       extraConfig.SupportSettings.HelpLink = "https://search.nixos.org";
52     };
53     environmentFile = makeMattermost {
54       mutableConfig = false;
55       extraConfig.SupportSettings.AboutLink = "https://example.org";
56       environmentFile = pkgs.writeText "mattermost-env" ''
57         MM_SUPPORTSETTINGS_ABOUTLINK=https://nixos.org
58       '';
59     };
60   };
62   testScript = let
63     expectConfig = jqExpression: pkgs.writeShellScript "expect-config" ''
64       set -euo pipefail
65       echo "Expecting config to match: "${lib.escapeShellArg jqExpression} >&2
66       curl ${lib.escapeShellArg url} >/dev/null
67       config="$(curl ${lib.escapeShellArg "${url}/api/v4/config/client?format=old"})"
68       echo "Config: $(echo "$config" | ${pkgs.jq}/bin/jq)" >&2
69       [[ "$(echo "$config" | ${pkgs.jq}/bin/jq -r ${lib.escapeShellArg ".SiteName == $siteName and .Version == ($mattermostName / $sep)[-1] and (${jqExpression})"} --arg siteName ${lib.escapeShellArg siteName} --arg mattermostName ${lib.escapeShellArg pkgs.mattermost.name} --arg sep '-')" = "true" ]]
70     '';
72     setConfig = jqExpression: pkgs.writeShellScript "set-config" ''
73       set -euo pipefail
74       mattermostConfig=/var/lib/mattermost/config/config.json
75       newConfig="$(${pkgs.jq}/bin/jq -r ${lib.escapeShellArg jqExpression} $mattermostConfig)"
76       rm -f $mattermostConfig
77       echo "$newConfig" > "$mattermostConfig"
78     '';
80   in
81   ''
82     start_all()
84     ## Mutable node tests ##
85     mutable.wait_for_unit("mattermost.service")
86     mutable.wait_for_open_port(8065)
88     # Get the initial config
89     mutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}")
91     # Edit the config
92     mutable.succeed("${setConfig ''.SupportSettings.AboutLink = "https://mattermost.com"''}")
93     mutable.succeed("${setConfig ''.SupportSettings.HelpLink = "https://nixos.org/nixos/manual"''}")
94     mutable.systemctl("restart mattermost.service")
95     mutable.wait_for_open_port(8065)
97     # AboutLink and HelpLink should be changed
98     mutable.succeed("${expectConfig ''.AboutLink == "https://mattermost.com" and .HelpLink == "https://nixos.org/nixos/manual"''}")
100     ## Mostly mutable node tests ##
101     mostlyMutable.wait_for_unit("mattermost.service")
102     mostlyMutable.wait_for_open_port(8065)
104     # Get the initial config
105     mostlyMutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org"''}")
107     # Edit the config
108     mostlyMutable.succeed("${setConfig ''.SupportSettings.AboutLink = "https://mattermost.com"''}")
109     mostlyMutable.succeed("${setConfig ''.SupportSettings.HelpLink = "https://nixos.org/nixos/manual"''}")
110     mostlyMutable.systemctl("restart mattermost.service")
111     mostlyMutable.wait_for_open_port(8065)
113     # AboutLink should be overridden by NixOS configuration; HelpLink should be what we set above
114     mostlyMutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://nixos.org/nixos/manual"''}")
116     ## Immutable node tests ##
117     immutable.wait_for_unit("mattermost.service")
118     immutable.wait_for_open_port(8065)
120     # Get the initial config
121     immutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}")
123     # Edit the config
124     immutable.succeed("${setConfig ''.SupportSettings.AboutLink = "https://mattermost.com"''}")
125     immutable.succeed("${setConfig ''.SupportSettings.HelpLink = "https://nixos.org/nixos/manual"''}")
126     immutable.systemctl("restart mattermost.service")
127     immutable.wait_for_open_port(8065)
129     # Our edits should be ignored on restart
130     immutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}")
133     ## Environment File node tests ##
134     environmentFile.wait_for_unit("mattermost.service")
135     environmentFile.wait_for_open_port(8065)
137     # Settings in the environment file should override settings set otherwise
138     environmentFile.succeed("${expectConfig ''.AboutLink == "https://nixos.org"''}")
139   '';