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";
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
63 expectConfig = jqExpression: pkgs.writeShellScript "expect-config" ''
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" ]]
72 setConfig = jqExpression: pkgs.writeShellScript "set-config" ''
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"
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"''}")
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"''}")
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"''}")
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"''}")