1 import ./make-test-python.nix ({ pkgs, lib, ... }:
5 url = "http://${host}:${port}";
6 siteName = "NixOS Smoke Tests, Inc.";
8 makeMattermost = mattermostConfig:
10 environment.systemPackages = [
16 "127.0.0.1" = [ host ];
18 services.mattermost = lib.recursiveUpdate {
21 listenAddress = "0.0.0.0:${port}";
24 SupportSettings.AboutLink = "https://nixos.org";
33 mutable = makeMattermost {
35 extraConfig.SupportSettings.HelpLink = "https://search.nixos.org";
37 mostlyMutable = makeMattermost {
39 preferNixConfig = true;
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";
49 immutable = makeMattermost {
50 mutableConfig = false;
51 extraConfig.SupportSettings.HelpLink = "https://search.nixos.org";
56 expectConfig = jqExpression: pkgs.writeShellScript "expect-config" ''
58 echo "Expecting config to match: "${lib.escapeShellArg jqExpression} >&2
59 curl ${lib.escapeShellArg url} >/dev/null
60 config="$(curl ${lib.escapeShellArg "${url}/api/v4/config/client?format=old"})"
61 echo "Config: $(echo "$config" | ${pkgs.jq}/bin/jq)" >&2
62 [[ "$(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" ]]
65 setConfig = jqExpression: pkgs.writeShellScript "set-config" ''
67 mattermostConfig=/var/lib/mattermost/config/config.json
68 newConfig="$(${pkgs.jq}/bin/jq -r ${lib.escapeShellArg jqExpression} $mattermostConfig)"
69 rm -f $mattermostConfig
70 echo "$newConfig" > "$mattermostConfig"
76 ## Mutable node tests ##
77 mutable.wait_for_unit("mattermost.service")
78 mutable.wait_for_open_port(8065)
80 # Get the initial config
81 mutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}")
84 mutable.succeed("${setConfig ''.SupportSettings.AboutLink = "https://mattermost.com"''}")
85 mutable.succeed("${setConfig ''.SupportSettings.HelpLink = "https://nixos.org/nixos/manual"''}")
86 mutable.systemctl("restart mattermost.service")
87 mutable.wait_for_open_port(8065)
89 # AboutLink and HelpLink should be changed
90 mutable.succeed("${expectConfig ''.AboutLink == "https://mattermost.com" and .HelpLink == "https://nixos.org/nixos/manual"''}")
92 ## Mostly mutable node tests ##
93 mostlyMutable.wait_for_unit("mattermost.service")
94 mostlyMutable.wait_for_open_port(8065)
96 # Get the initial config
97 mostlyMutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org"''}")
100 mostlyMutable.succeed("${setConfig ''.SupportSettings.AboutLink = "https://mattermost.com"''}")
101 mostlyMutable.succeed("${setConfig ''.SupportSettings.HelpLink = "https://nixos.org/nixos/manual"''}")
102 mostlyMutable.systemctl("restart mattermost.service")
103 mostlyMutable.wait_for_open_port(8065)
105 # AboutLink should be overridden by NixOS configuration; HelpLink should be what we set above
106 mostlyMutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://nixos.org/nixos/manual"''}")
108 ## Immutable node tests ##
109 immutable.wait_for_unit("mattermost.service")
110 immutable.wait_for_open_port(8065)
112 # Get the initial config
113 immutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}")
116 immutable.succeed("${setConfig ''.SupportSettings.AboutLink = "https://mattermost.com"''}")
117 immutable.succeed("${setConfig ''.SupportSettings.HelpLink = "https://nixos.org/nixos/manual"''}")
118 immutable.systemctl("restart mattermost.service")
119 immutable.wait_for_open_port(8065)
121 # Our edits should be ignored on restart
122 immutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}")