mattermost: enable test suite, mmctl support, and plugin building

Add the following passthrus:

- mattermost.withTests (builds with tests but takes a while)
- mattermost.withoutTests (builds without tests but is shorter)
- mattermost.tests.mattermostWithTests
- mattermost.buildPlugin (builds a plugin from source)

Enable the mmctl build, and its tests, if selected.

authored by Morgan Jones and committed by Valentin Gagarin 80093811 5792ff19

+670 -52
+153
pkgs/by-name/ma/mattermost/build-plugin.nix
··· 1 + { 2 + lib, 3 + stdenv, 4 + mattermost, 5 + nodejs, 6 + writeShellScriptBin, 7 + buildGoModule, 8 + golangci-lint, 9 + gotestsum, 10 + fetchNpmDeps, 11 + npmHooks, 12 + npm-lockfile-fix, 13 + }: 14 + 15 + { 16 + # The name of the plugin. 17 + pname, 18 + # The plugin version. 19 + version, 20 + # The plugin source. 21 + src, 22 + 23 + # True to ignore golangci-lint warnings. By default set to true 24 + # since plugins warn about the Mattermost interface but build fine. 25 + ignoreGoLintWarnings ? true, 26 + 27 + # The hash of the gomod vendor directory. 28 + vendorHash ? lib.fakeHash, 29 + 30 + # True to build the webapp. 31 + buildWebapp ? true, 32 + 33 + # The NPM dependency hash. 34 + npmDepsHash ? lib.fakeHash, 35 + 36 + # Any extra attributes to pass to buildGoModule. 37 + extraGoModuleAttrs ? { }, 38 + }: 39 + 40 + let 41 + fakeGit = writeShellScriptBin "git" '' 42 + case "$1" in 43 + rev-parse|describe|tag) 44 + echo ${lib.escapeShellArg version} ;; 45 + config) 46 + echo ${lib.escapeShellArg pname} ;; 47 + *) ;; 48 + esac 49 + ''; 50 + 51 + fake-golangci-lint = writeShellScriptBin "golangci-lint" '' 52 + set -uo pipefail 53 + ${lib.getExe golangci-lint} "$@" 54 + result=$? 55 + echo "golangci-lint returned: $result" >&2 56 + ${lib.optionalString (ignoreGoLintWarnings) '' 57 + if [ $result != 0 ]; then 58 + cat <<EOF >&2 59 + Ignoring return value since ignoreGoLintWarnings was true. 60 + Tell this plugin author to fix their lint. 61 + EOF 62 + result=0 63 + fi 64 + ''} 65 + exit $result 66 + ''; 67 + in 68 + buildGoModule ( 69 + rec { 70 + name = "${pname}-${version}.tar.gz"; 71 + inherit version src vendorHash; 72 + 73 + npmDeps = 74 + if buildWebapp then 75 + fetchNpmDeps { 76 + src = "${src}/webapp"; 77 + hash = npmDepsHash; 78 + forceGitDeps = true; 79 + postFetch = '' 80 + ${lib.getExe npm-lockfile-fix} package-lock.json 81 + ''; 82 + } 83 + else 84 + null; 85 + 86 + makeCacheWritable = true; 87 + forceGitDeps = true; 88 + 89 + overrideModAttrs = final: { 90 + preBuild = '' 91 + go mod tidy 92 + ''; 93 + 94 + # Adding the NPM config hook here breaks things, and isn't even needed. 95 + nativeBuildInputs = lib.lists.remove npmHooks.npmConfigHook final.nativeBuildInputs; 96 + }; 97 + 98 + prePatch = lib.optionalString buildWebapp '' 99 + # Move important node.js files up a level and symlink the originals so the setup hook finds them 100 + for file in package.json package-lock.json node_modules; do 101 + if [ -f "webapp/$file" ]; then 102 + mv "webapp/$file" . 103 + fi 104 + (cd webapp && ln -vsf "../$file") 105 + done 106 + 107 + # Don't allow Go installation in the sandbox, but also don't fail 108 + substituteInPlace Makefile --replace-warn '$(GO) install' '@echo $(GO) install' 109 + ''; 110 + 111 + nativeBuildInputs = [ 112 + fakeGit 113 + nodejs 114 + npmHooks.npmConfigHook 115 + ]; 116 + 117 + buildInputs = [ mattermost ]; 118 + 119 + preBuild = '' 120 + # Or else Babel doesn't run. 121 + export NODE_OPTIONS=--openssl-legacy-provider 122 + 123 + # Only build GOOS and GOARCH plugins so we aren't 124 + # spitting out FreeBSD/Windows/Darwin executables we don't use. 125 + export MM_SERVICESETTINGS_ENABLEDEVELOPER=true 126 + ''; 127 + 128 + buildPhase = '' 129 + runHook preBuild 130 + 131 + # These dependencies are ordinarily fetched via the Makefile, making 132 + # $(GO) install only echo means we still need to install them. 133 + mkdir -p bin 134 + ln -sf ${lib.getExe fake-golangci-lint} bin/golangci-lint 135 + ln -sf ${lib.getExe gotestsum} bin/gotestsum 136 + 137 + # Do the build. 138 + make 139 + 140 + runHook postBuild 141 + ''; 142 + 143 + installPhase = '' 144 + plugin="$(ls dist/*.tar.gz | tail -n1)" 145 + if [ -z "$plugin" ] || [ ! -f "$plugin" ]; then 146 + echo "No plugin tarball in dist folder!" >&2 147 + exit 1 148 + fi 149 + cp -av "$plugin" $out 150 + ''; 151 + } 152 + // extraGoModuleAttrs 153 + )
+118 -52
pkgs/by-name/ma/mattermost/package.nix
··· 1 1 { 2 2 lib, 3 + callPackage, 4 + stdenvNoCC, 3 5 buildGoModule, 4 6 fetchFromGitHub, 5 7 buildNpmPackage, ··· 24 26 }, 25 27 }: 26 28 27 - buildGoModule rec { 29 + let 30 + /* 31 + Helper function that sets the `withTests` and `withoutTests` passthru correctly, 32 + and returns the version with tests. 33 + 34 + The primary reason to use this helper over reindenting the whole file is to avoid 35 + lots of manual backporting when the update script runs. 36 + */ 37 + buildMattermost = 38 + { passthru, ... }@args: 39 + let 40 + # Joins the webapp and Matermost derivation together. 41 + # That way patches to the webapp won't cause a rebuild of the server. 42 + wrapMattermost = 43 + server: 44 + stdenvNoCC.mkDerivation { 45 + pname = "${server.pname}-wrapped"; 46 + inherit (server) version; 47 + inherit server; 48 + inherit (server) webapp; 49 + 50 + dontUnpack = true; 51 + 52 + # Just link all the server and webapp root directories together. 53 + installPhase = '' 54 + mkdir -p $out 55 + for dir in "$server" "$webapp"; do 56 + for path in "$dir"/*; do 57 + ln -s "$path" "$out/$(basename -- "$path")" 58 + done 59 + done 60 + ''; 61 + 62 + passthru = finalPassthru // { 63 + inherit server; 64 + inherit (server) webapp; 65 + }; 66 + 67 + inherit (server) meta; 68 + }; 69 + finalPassthru = 70 + let 71 + withoutTestsUnwrapped = buildGoModule (args // { passthru = finalPassthru; }); 72 + withTestsUnwrapped = callPackage ./tests.nix { mattermost = withoutTestsUnwrapped; }; 73 + in 74 + lib.recursiveUpdate passthru rec { 75 + withoutTests = wrapMattermost withoutTestsUnwrapped; 76 + withTests = wrapMattermost withTestsUnwrapped; 77 + tests.mattermostWithTests = withTests; 78 + }; 79 + in 80 + finalPassthru.withTests; 81 + in 82 + buildMattermost rec { 28 83 pname = "mattermost"; 29 84 inherit (versionInfo) version; 30 85 ··· 64 119 # We use go 1.22's workspace vendor command, which is not yet available 65 120 # in the default version of go used in nixpkgs, nor is it used by upstream: 66 121 # https://github.com/mattermost/mattermost/issues/26221#issuecomment-1945351597 67 - overrideModAttrs = ( 68 - _: { 69 - buildPhase = '' 70 - make setup-go-work 71 - go work vendor -e 72 - ''; 73 - } 74 - ); 122 + overrideModAttrs = _: { 123 + buildPhase = '' 124 + make setup-go-work 125 + go work vendor -e -v 126 + ''; 127 + }; 75 128 76 129 npmDeps = fetchNpmDeps { 77 130 inherit src; ··· 81 134 forceGitDeps = true; 82 135 }; 83 136 84 - webapp = buildNpmPackage rec { 85 - pname = "mattermost-webapp"; 86 - inherit version src; 87 - 88 - sourceRoot = "${src.name}/webapp"; 89 - 90 - # Remove deprecated image-webpack-loader causing build failures 91 - # See: https://github.com/tcoopman/image-webpack-loader#deprecated 92 - postPatch = '' 93 - substituteInPlace channels/webpack.config.js \ 94 - --replace-fail 'options: {}' 'options: { disable: true }' 95 - ''; 96 - 97 - npmDepsHash = npmDeps.hash; 98 - makeCacheWritable = true; 99 - forceGitDeps = true; 100 - 101 - npmRebuildFlags = [ "--ignore-scripts" ]; 102 - 103 - buildPhase = '' 104 - runHook preBuild 105 - 106 - npm run build --workspace=platform/types 107 - npm run build --workspace=platform/client 108 - npm run build --workspace=platform/components 109 - npm run build --workspace=channels 110 - 111 - runHook postBuild 112 - ''; 113 - 114 - installPhase = '' 115 - runHook preInstall 116 - 117 - mkdir -p $out 118 - cp -a channels/dist/* $out 119 - 120 - runHook postInstall 121 - ''; 122 - }; 123 - 124 137 inherit (versionInfo) vendorHash; 125 138 126 139 modRoot = "./server"; ··· 128 141 make setup-go-work 129 142 ''; 130 143 131 - subPackages = [ "cmd/mattermost" ]; 144 + subPackages = [ 145 + "cmd/mattermost" 146 + "cmd/mmctl" 147 + ]; 132 148 133 149 tags = [ "production" ]; 134 150 ··· 147 163 shopt -s extglob 148 164 mkdir -p $out/{i18n,fonts,templates,config} 149 165 150 - # Link in the client and copy the language packs. 151 - ln -sf $webapp $out/client 166 + # Copy the language packs. 152 167 cp -a $src/server/i18n/* $out/i18n/ 153 168 154 169 # Fonts have the execute bit set, remove it. ··· 162 177 go run -tags production ./scripts/config_generator 163 178 ''; 164 179 180 + doInstallCheck = true; 181 + installCheckPhase = '' 182 + for subPackage in $subPackages; do 183 + "$out/bin/$(basename -- "$subPackage")" version | grep "$version" 184 + done 185 + ''; 186 + 165 187 passthru = { 166 188 updateScript = nix-update-script { 167 189 extraArgs = ··· 175 197 ]; 176 198 }; 177 199 tests.mattermost = nixosTests.mattermost; 200 + 201 + # Builds a Mattermost plugin. 202 + buildPlugin = callPackage ./build-plugin.nix { }; 203 + 204 + # Builds the webapp. 205 + webapp = buildNpmPackage rec { 206 + pname = "mattermost-webapp"; 207 + inherit version src; 208 + 209 + sourceRoot = "${src.name}/webapp"; 210 + 211 + # Remove deprecated image-webpack-loader causing build failures 212 + # See: https://github.com/tcoopman/image-webpack-loader#deprecated 213 + postPatch = '' 214 + substituteInPlace channels/webpack.config.js \ 215 + --replace-fail 'options: {}' 'options: { disable: true }' 216 + ''; 217 + 218 + npmDepsHash = npmDeps.hash; 219 + makeCacheWritable = true; 220 + forceGitDeps = true; 221 + 222 + npmRebuildFlags = [ "--ignore-scripts" ]; 223 + 224 + buildPhase = '' 225 + runHook preBuild 226 + 227 + npm run build --workspace=platform/types 228 + npm run build --workspace=platform/client 229 + npm run build --workspace=platform/components 230 + npm run build --workspace=channels 231 + 232 + runHook postBuild 233 + ''; 234 + 235 + installPhase = '' 236 + runHook preInstall 237 + 238 + mkdir -p $out/client 239 + cp -a channels/dist/* $out/client 240 + 241 + runHook postInstall 242 + ''; 243 + }; 178 244 }; 179 245 180 246 meta = with lib; {
+399
pkgs/by-name/ma/mattermost/tests.nix
··· 1 + { 2 + lib, 3 + stdenv, 4 + mattermost, 5 + gotestsum, 6 + which, 7 + postgresql, 8 + mariadb, 9 + redis, 10 + curl, 11 + nettools, 12 + runtimeShell, 13 + }: 14 + 15 + let 16 + inherit (lib.lists) optionals; 17 + inherit (lib.strings) versionAtLeast; 18 + is10 = version: versionAtLeast version "10.0"; 19 + in 20 + mattermost.overrideAttrs ( 21 + final: prev: { 22 + doCheck = true; 23 + checkTargets = [ 24 + "test-server" 25 + "test-mmctl" 26 + ]; 27 + nativeCheckInputs = [ 28 + which 29 + postgresql 30 + mariadb 31 + redis 32 + curl 33 + nettools 34 + gotestsum 35 + ]; 36 + 37 + postPatch = 38 + prev.postPatch or "" 39 + + '' 40 + # Just echo install/get/mod commands in the Makefile, since the dependencies are locked. 41 + substituteInPlace server/Makefile \ 42 + --replace-warn '$(GO) install' '@echo $(GO) install' \ 43 + --replace-warn '$(GO) get' '@echo $(GO) get' \ 44 + --replace-warn '$(GO) get' '@echo $(GO) mod' 45 + # mmctl tests shell out by writing a bash script to a tempfile 46 + substituteInPlace server/cmd/mmctl/commands/config_e2e_test.go \ 47 + --replace-fail '#!/bin/bash' '#!${runtimeShell}' 48 + ''; 49 + 50 + # Make sure we disable tests that are broken. 51 + # Use: `nix log <drv> | grep FAIL: | awk '{print $3}' | sort` 52 + # and then try to pick the most specific test set to disable, such as: 53 + # X TestFoo 54 + # X TestFoo/TestBar 55 + # -> TestFoo/TestBar/baz_test 56 + disabledTests = 57 + [ 58 + # All these plugin tests for mmctl reach out to the marketplace, which is impossible in the sandbox 59 + "TestMmctlE2ESuite/TestPluginDeleteCmd/Delete_Plugin/SystemAdminClient" 60 + "TestMmctlE2ESuite/TestPluginDeleteCmd/Delete_Plugin/LocalClient" 61 + "TestMmctlE2ESuite/TestPluginDeleteCmd/Delete_a_Plugin_without_permissions" 62 + "TestMmctlE2ESuite/TestPluginDeleteCmd/Delete_Unknown_Plugin/SystemAdminClient" 63 + "TestMmctlE2ESuite/TestPluginDeleteCmd/Delete_Unknown_Plugin/LocalClient" 64 + "TestMmctlE2ESuite/TestPluginInstallURLCmd/install_new_plugins/SystemAdminClient" 65 + "TestMmctlE2ESuite/TestPluginInstallURLCmd/install_new_plugins/LocalClient" 66 + "TestMmctlE2ESuite/TestPluginInstallURLCmd/install_an_already_installed_plugin_without_force/SystemAdminClient" 67 + "TestMmctlE2ESuite/TestPluginInstallURLCmd/install_an_already_installed_plugin_without_force/LocalClient" 68 + "TestMmctlE2ESuite/TestPluginInstallURLCmd/install_an_already_installed_plugin_with_force/SystemAdminClient" 69 + "TestMmctlE2ESuite/TestPluginInstallURLCmd/install_an_already_installed_plugin_with_force/LocalClient" 70 + "TestMmctlE2ESuite/TestPluginMarketplaceInstallCmd/install_a_plugin/SystemAdminClient" 71 + "TestMmctlE2ESuite/TestPluginMarketplaceInstallCmd/install_a_plugin/LocalClient" 72 + "TestMmctlE2ESuite/TestPluginMarketplaceListCmd/List_Marketplace_Plugins_for_Admin_User/SystemAdminClient" 73 + "TestMmctlE2ESuite/TestPluginMarketplaceListCmd/List_Marketplace_Plugins_for_Admin_User/LocalClient" 74 + 75 + # Seems to just be broken. 76 + "TestMmctlE2ESuite/TestPreferenceUpdateCmd" 77 + 78 + # Has a hardcoded "google.com" test which also verifies that the address isn't loopback, 79 + # so we also can't just substituteInPlace to one that will resolve 80 + "TestDialContextFilter" 81 + 82 + # No interfaces but loopback in the sandbox, so returns empty 83 + "TestGetServerIPAddress" 84 + 85 + # S3 bucket tests (needs Minio) 86 + "TestInsecureMakeBucket" 87 + "TestMakeBucket" 88 + "TestListDirectory" 89 + "TestTimeout" 90 + "TestStartServerNoS3Bucket" 91 + "TestS3TestConnection" 92 + "TestS3FileBackendTestSuite" 93 + "TestS3FileBackendTestSuiteWithEncryption" 94 + 95 + # Mail tests (needs a SMTP server) 96 + "TestSendMailUsingConfig" 97 + "TestSendMailUsingConfigAdvanced" 98 + "TestSendMailWithEmbeddedFilesUsingConfig" 99 + "TestSendCloudWelcomeEmail" 100 + "TestMailConnectionAdvanced" 101 + "TestMailConnectionFromConfig" 102 + "TestEmailTest" 103 + "TestBasicAPIPlugins/test_send_mail_plugin" 104 + 105 + # Seems to be unreliable 106 + "TestPluginAPIUpdateUserPreferences" 107 + "TestPluginAPIGetUserPreferences" 108 + 109 + # These invite tests try to send a welcome email and we don't have a SMTP server up. 110 + "TestInviteUsersToTeam" 111 + "TestInviteGuestsToTeam" 112 + "TestSendInviteEmails" 113 + "TestDeliver" 114 + 115 + # https://github.com/mattermost/mattermost/issues/29184 116 + "TestUpAndDownMigrations/Should_be_reversible_for_mysql" 117 + ] 118 + ++ optionals (is10 final.version) [ 119 + ## mattermostLatest test ignores 120 + 121 + # These bot related tests appear to be broken. 122 + "TestCreateBot" 123 + "TestPatchBot" 124 + "TestGetBot" 125 + "TestEnableBot" 126 + "TestDisableBot" 127 + "TestAssignBot" 128 + "TestConvertBotToUser" 129 + 130 + # Need Elasticsearch or Opensearch 131 + "TestBlevePurgeIndexes" 132 + "TestOpensearchAggregation" 133 + "TestOpensearchInterfaceTestSuite" 134 + "TestOpenSearchIndexerJobIsEnabled" 135 + "TestOpenSearchIndexerPending" 136 + "TestBulkProcessor" 137 + "TestElasticsearchAggregation" 138 + "TestElasticsearchInterfaceTestSuite" 139 + "TestElasticSearchIndexerJobIsEnabled" 140 + "TestElasticSearchIndexerPending" 141 + 142 + # Appear to be broken. 143 + "TestSessionStore/MySQL/SessionGetWithDeviceId" 144 + "TestSessionStore/MySQL/GetMobileSessionMetadata" 145 + ] 146 + ++ optionals (!stdenv.isx86_64) [ 147 + # aarch64: invalid operating system or processor architecture 148 + "TestCanIUpgradeToE0" 149 + ]; 150 + 151 + preCheck = '' 152 + cleanup() { 153 + runHook postCheck 154 + } 155 + trap cleanup EXIT 156 + 157 + # Runs an iteration of the wait loop. 158 + # Returns 0 if we should retry, 1 otherwise. 159 + _wait_loop() { 160 + local process="$1" 161 + local direction="$2" 162 + echo "Waiting for $process to go $direction ($_TRIES attempt(s) left)..." >&2 163 + _TRIES=$((_TRIES-1)) 164 + if [ $_TRIES -le 0 ]; then 165 + return 1 166 + else 167 + sleep 1 168 + return 0 169 + fi 170 + } 171 + 172 + # Waits on a command named '$1' with direction '$2'. 173 + # The rest of the command is specified in $@. 174 + # If the direction is up, waits for the command to succeed at 1 second intervals. 175 + # If it's down, waits for the command to fail at 1 second intervals. 176 + # Uses a maximum of 5 iterations. Returns 0 if all was ok, or 1 if we timed out. 177 + wait_cmd() { 178 + local process="$1" 179 + local direction="$2" 180 + local tries=10 181 + _TRIES=$tries 182 + shift; shift 183 + if [ "$direction" == "up" ]; then 184 + while ! "$@" &>/dev/null; do 185 + if ! _wait_loop "$process" "$direction"; then 186 + break 187 + fi 188 + done 189 + else 190 + while "$@" &>/dev/null; do 191 + if ! _wait_loop "$process" "$direction"; then 192 + break 193 + fi 194 + done 195 + fi 196 + 197 + if [ $_TRIES -le 0 ]; then 198 + echo "Timed out after $tries tries" >&2 199 + return 1 200 + else 201 + echo "OK, $process went $direction." >&2 202 + return 0 203 + fi 204 + } 205 + 206 + # Waits for MySQL to come up or down. 207 + wait_mysql() { 208 + wait_cmd mysql "$1" mysqladmin ping 209 + } 210 + 211 + # Waits for Postgres to come up or down. 212 + wait_postgres() { 213 + wait_cmd postgres "$1" pg_isready -h localhost 214 + } 215 + 216 + # Waits for Redis to come up or down. 217 + wait_redis() { 218 + wait_cmd redis "$1" redis-cli ping 219 + } 220 + 221 + # Starts MySQL. 222 + start_mysql() { 223 + echo "Starting MySQL at $MYSQL_HOME" >&2 224 + mysqld & 225 + mysql_pid=$! 226 + echo "... PID $mysql_pid" >&2 227 + wait_mysql up 228 + } 229 + 230 + # Stops MySQL. 231 + stop_mysql() { 232 + if [ "$mysql_pid" -gt 0 ]; then 233 + echo "Terminating MySQL at $MYSQL_HOME (PID $mysql_pid)" >&2 234 + mysqladmin --host=127.0.0.1 --user=root --password=mostest --wait-for-all-slaves --shutdown-timeout=30 shutdown 235 + wait_mysql down 236 + wait_cmd 'mysql pid' down kill -0 "$mysql_pid" 237 + 238 + # Make sure the worker PID went down too (but it may be already gone). 239 + local worker_pid="$(<"$MYSQL_HOME"/mysqld.pid || echo 0)" 240 + if [ -n "$worker_pid" ] && [ $worker_pid -gt 0 ]; then 241 + wait_cmd 'mysql workers' down kill -0 "$worker_pid" 242 + fi 243 + 244 + mysql_pid=0 245 + fi 246 + } 247 + 248 + # Starts Postgres. 249 + start_postgres() { 250 + echo "Starting Postgres at $PGDATA" >&2 251 + pg_ctl start 252 + wait_postgres up 253 + } 254 + 255 + # Stops Postgres. 256 + stop_postgres() { 257 + echo "Terminating Postgres at $PGDATA" >&2 258 + pg_ctl stop 259 + wait_postgres down 260 + } 261 + 262 + # Starts redis. 263 + start_redis() { 264 + echo "Starting Redis" >&2 265 + (cd "$REDIS_HOME" && exec redis-server ./redis.conf) & 266 + redis_pid=$! 267 + echo "... PID $redis_pid" >&2 268 + wait_redis up 269 + } 270 + 271 + # Stops redis. 272 + stop_redis() { 273 + echo "Stopping Redis" >&2 274 + kill -TERM "$redis_pid" >&2 275 + wait_redis down 276 + redis_pid=0 277 + } 278 + 279 + # Configure MySQL. 280 + export MYSQL_HOME="$NIX_BUILD_TOP/.mysql" 281 + mkdir -p "$MYSQL_HOME" 282 + cat <<EOF >"$MYSQL_HOME/my.cnf" 283 + [client] 284 + port = 3306 285 + default-character-set = utf8mb4 286 + socket = $MYSQL_HOME/mysqld.sock 287 + 288 + [mysqld] 289 + skip-host-cache 290 + skip-name-resolve 291 + basedir = ${mariadb} 292 + datadir = $MYSQL_HOME/ 293 + pid-file = $MYSQL_HOME/mysqld.pid 294 + socket = $MYSQL_HOME/mysqld.sock 295 + port = 3306 296 + explicit_defaults_for_timestamp 297 + collation-server = utf8mb4_general_ci 298 + init-connect = 'SET NAMES utf8mb4' 299 + character-set-server = utf8mb4 300 + EOF 301 + 302 + # Start MySQL. 303 + mysql_install_db --skip-name-resolve --auth-root-authentication-method=normal 304 + start_mysql 305 + 306 + # Init MySQL. 307 + cat <<EOF | mysql --defaults-file="$MYSQL_HOME/my.cnf" -u root -v 308 + -- This is the admin password for tests; see the docker-compose: 309 + -- https://github.com/mattermost/mattermost/blob/v${final.version}/server/docker-compose.yaml 310 + create user if not exists 'mmuser' identified by 'mostest'; 311 + create database if not exists mattermost_test; 312 + grant all privileges on *.* to 'mmuser' with grant option; 313 + 314 + -- Also need to set up root (tests seem to override the user to root) 315 + alter user 'root'@'127.0.0.1' identified by 'mostest'; 316 + 317 + flush privileges; 318 + show grants for 'root'@'127.0.0.1'; 319 + show grants for 'mmuser'; 320 + EOF 321 + 322 + # Need to change this so we use 127.0.0.1 in tests. 323 + export TEST_DATABASE_MYSQL_DSN='root:mostest@tcp(127.0.0.1:3306)/mattermost_test?charset=utf8mb4&readTimeout=30s&writeTimeout=30s' 324 + 325 + # Start Postgres. 326 + export PGDATA="$NIX_BUILD_TOP/.postgres" 327 + initdb -U postgres 328 + mkdir -p "$PGDATA/run" 329 + cat <<EOF >> "$PGDATA/postgresql.conf" 330 + unix_socket_directories = '$PGDATA/run' 331 + max_connections = 256 332 + shared_buffers = 96MB 333 + EOF 334 + start_postgres 335 + 336 + # Init Postgres. 337 + cat <<EOF | psql -U postgres -h localhost 338 + -- This is the admin password for tests; see the docker-compose: 339 + -- https://github.com/mattermost/mattermost/blob/v${final.version}/server/docker-compose.yaml 340 + create user mmuser superuser password 'mostest'; 341 + create database mattermost_test; 342 + grant all on database mattermost_test to mmuser; 343 + alter database mattermost_test owner to mmuser; 344 + EOF 345 + 346 + # Configure Redis. 347 + export REDIS_HOME="$NIX_BUILD_TOP/.redis" 348 + mkdir -p "$REDIS_HOME" 349 + cat <<EOF > "$REDIS_HOME/redis.conf" 350 + bind 127.0.0.1 351 + port 6379 352 + protected-mode no 353 + EOF 354 + 355 + # Start Redis. 356 + start_redis 357 + 358 + # Use gotestsum from nixpkgs instead of installing it ourselves. 359 + mkdir -p bin 360 + ln -s "$(which gotestsum)" bin/gotestsum 361 + ''; 362 + 363 + checkPhase = '' 364 + runHook preCheck 365 + 366 + # Ensure we parallelize the tests, and skip the correct ones. 367 + # Spaces are important here due to how the Makefile works. 368 + export GOFLAGS=" -parallel=$NIX_BUILD_CORES -skip='$(echo "$disabledTests" | tr ' ' '|')' " 369 + 370 + # ce n'est pas un conteneur 371 + MMCTL_TESTFLAGS="$GOFLAGS" MM_NO_DOCKER=true make $checkTargets 372 + 373 + runHook postCheck 374 + ''; 375 + 376 + postCheck = '' 377 + # Clean up MySQL. 378 + if [ -d "$MYSQL_HOME" ]; then 379 + stop_mysql 380 + rm -rf "$MYSQL_HOME" 381 + fi 382 + 383 + # Clean up Postgres. 384 + if [ -d "$PGDATA" ]; then 385 + stop_postgres 386 + rm -rf "$PGDATA" 387 + fi 388 + 389 + # Clean up Redis. 390 + if [ -d "$REDIS_HOME" ]; then 391 + stop_redis 392 + rm -rf "$REDIS_HOME" 393 + fi 394 + 395 + # Delete the gotestsum link. 396 + rm -f bin/gotestsum 397 + ''; 398 + } 399 + )