···
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 = [
15
+
networking.hosts = {
16
+
"127.0.0.1" = [ host ];
18
+
services.mattermost = lib.recursiveUpdate {
21
+
listenAddress = "0.0.0.0:${port}";
24
+
SupportSettings.AboutLink = "https://nixos.org";
30
+
name = "mattermost";
33
+
mutable = makeMattermost {
34
+
mutableConfig = true;
35
+
extraConfig.SupportSettings.HelpLink = "https://search.nixos.org";
37
+
mostlyMutable = makeMattermost {
38
+
mutableConfig = true;
39
+
preferNixConfig = true;
41
+
immutable = makeMattermost {
42
+
mutableConfig = false;
43
+
extraConfig.SupportSettings.HelpLink = "https://search.nixos.org";
48
+
expectConfig = jqExpression: pkgs.writeShellScript "expect-config" ''
50
+
echo "Expecting config to match: "${lib.escapeShellArg jqExpression} >&2
51
+
curl ${lib.escapeShellArg url} >/dev/null
52
+
config="$(curl ${lib.escapeShellArg "${url}/api/v4/config/client?format=old"})"
53
+
echo "Config: $(echo "$config" | ${pkgs.jq}/bin/jq)" >&2
54
+
[[ "$(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" ]]
57
+
setConfig = jqExpression: pkgs.writeShellScript "set-config" ''
59
+
mattermostConfig=/var/lib/mattermost/config/config.json
60
+
newConfig="$(${pkgs.jq}/bin/jq -r ${lib.escapeShellArg jqExpression} $mattermostConfig)"
61
+
rm -f $mattermostConfig
62
+
echo "$newConfig" > "$mattermostConfig"
68
+
## Mutable node tests ##
69
+
mutable.wait_for_unit("mattermost.service")
70
+
mutable.wait_for_open_port(8065)
72
+
# Get the initial config
73
+
mutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}")
76
+
mutable.succeed("${setConfig ''.SupportSettings.AboutLink = "https://mattermost.com"''}")
77
+
mutable.succeed("${setConfig ''.SupportSettings.HelpLink = "https://nixos.org/nixos/manual"''}")
78
+
mutable.systemctl("restart mattermost.service")
79
+
mutable.wait_for_open_port(8065)
81
+
# AboutLink and HelpLink should be changed
82
+
mutable.succeed("${expectConfig ''.AboutLink == "https://mattermost.com" and .HelpLink == "https://nixos.org/nixos/manual"''}")
84
+
## Mostly mutable node tests ##
85
+
mostlyMutable.wait_for_unit("mattermost.service")
86
+
mostlyMutable.wait_for_open_port(8065)
88
+
# Get the initial config
89
+
mostlyMutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org"''}")
92
+
mostlyMutable.succeed("${setConfig ''.SupportSettings.AboutLink = "https://mattermost.com"''}")
93
+
mostlyMutable.succeed("${setConfig ''.SupportSettings.HelpLink = "https://nixos.org/nixos/manual"''}")
94
+
mostlyMutable.systemctl("restart mattermost.service")
95
+
mostlyMutable.wait_for_open_port(8065)
97
+
# AboutLink should be overridden by NixOS configuration; HelpLink should be what we set above
98
+
mostlyMutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://nixos.org/nixos/manual"''}")
100
+
## Immutable node tests ##
101
+
immutable.wait_for_unit("mattermost.service")
102
+
immutable.wait_for_open_port(8065)
104
+
# Get the initial config
105
+
immutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}")
108
+
immutable.succeed("${setConfig ''.SupportSettings.AboutLink = "https://mattermost.com"''}")
109
+
immutable.succeed("${setConfig ''.SupportSettings.HelpLink = "https://nixos.org/nixos/manual"''}")
110
+
immutable.systemctl("restart mattermost.service")
111
+
immutable.wait_for_open_port(8065)
113
+
# Our edits should be ignored on restart
114
+
immutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}")