at 23.05-pre 4.9 kB view raw
1import ./make-test-python.nix ({ pkgs, lib, ... }: 2let 3 host = "smoke.test"; 4 port = "8065"; 5 url = "http://${host}:${port}"; 6 siteName = "NixOS Smoke Tests, Inc."; 7 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 }; 28in 29{ 30 name = "mattermost"; 31 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 }; 54 55 testScript = let 56 expectConfig = jqExpression: pkgs.writeShellScript "expect-config" '' 57 set -euo pipefail 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" ]] 63 ''; 64 65 setConfig = jqExpression: pkgs.writeShellScript "set-config" '' 66 set -euo pipefail 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" 71 ''; 72 in 73 '' 74 start_all() 75 76 ## Mutable node tests ## 77 mutable.wait_for_unit("mattermost.service") 78 mutable.wait_for_open_port(8065) 79 80 # Get the initial config 81 mutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}") 82 83 # Edit the config 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) 88 89 # AboutLink and HelpLink should be changed 90 mutable.succeed("${expectConfig ''.AboutLink == "https://mattermost.com" and .HelpLink == "https://nixos.org/nixos/manual"''}") 91 92 ## Mostly mutable node tests ## 93 mostlyMutable.wait_for_unit("mattermost.service") 94 mostlyMutable.wait_for_open_port(8065) 95 96 # Get the initial config 97 mostlyMutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org"''}") 98 99 # Edit the config 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) 104 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"''}") 107 108 ## Immutable node tests ## 109 immutable.wait_for_unit("mattermost.service") 110 immutable.wait_for_open_port(8065) 111 112 # Get the initial config 113 immutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}") 114 115 # Edit the config 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) 120 121 # Our edits should be ignored on restart 122 immutable.succeed("${expectConfig ''.AboutLink == "https://nixos.org" and .HelpLink == "https://search.nixos.org"''}") 123 ''; 124})