diff options
author | George Goldberg <george@gberg.me> | 2018-02-13 13:35:52 +0000 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2018-02-13 13:46:01 +0000 |
commit | 5c101253c5987743cf1b3a8fe68814d748070622 (patch) | |
tree | e2632505d051e7d15d6daf974ed8ac92095f82fe /cmd/platform/server_test.go | |
parent | b7fc3d7d35ca4dd16097715a66463392a1dfaf0a (diff) | |
parent | d88d2bc2ed3aefa68b5ed2942f493ae42bb40bfa (diff) | |
download | chat-5c101253c5987743cf1b3a8fe68814d748070622.tar.gz chat-5c101253c5987743cf1b3a8fe68814d748070622.tar.bz2 chat-5c101253c5987743cf1b3a8fe68814d748070622.zip |
Merge branch 'master' into advanced-permissions-phase-1
Diffstat (limited to 'cmd/platform/server_test.go')
-rw-r--r-- | cmd/platform/server_test.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/cmd/platform/server_test.go b/cmd/platform/server_test.go new file mode 100644 index 000000000..15f9a357a --- /dev/null +++ b/cmd/platform/server_test.go @@ -0,0 +1,72 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package main + +import ( + "io/ioutil" + "os" + "syscall" + "testing" + + "github.com/mattermost/mattermost-server/jobs" + "github.com/mattermost/mattermost-server/utils" + "github.com/stretchr/testify/require" +) + +type ServerTestHelper struct { + configPath string + disableConfigWatch bool + interruptChan chan os.Signal + originalInterval int +} + +func SetupServerTest() *ServerTestHelper { + // Build a channel that will be used by the server to receive system signals… + interruptChan := make(chan os.Signal, 1) + // …and sent it immediately a SIGINT value. + // This will make the server loop stop as soon as it started successfully. + interruptChan <- syscall.SIGINT + + // Let jobs poll for termination every 0.2s (instead of every 15s by default) + // Otherwise we would have to wait the whole polling duration before the test + // terminates. + originalInterval := jobs.DEFAULT_WATCHER_POLLING_INTERVAL + jobs.DEFAULT_WATCHER_POLLING_INTERVAL = 200 + + th := &ServerTestHelper{ + configPath: utils.FindConfigFile("config.json"), + disableConfigWatch: true, + interruptChan: interruptChan, + originalInterval: originalInterval, + } + return th +} + +func (th *ServerTestHelper) TearDownServerTest() { + jobs.DEFAULT_WATCHER_POLLING_INTERVAL = th.originalInterval +} + +func TestRunServerSuccess(t *testing.T) { + th := SetupServerTest() + defer th.TearDownServerTest() + + err := runServer(th.configPath, th.disableConfigWatch, th.interruptChan) + require.NoError(t, err) +} + +func TestRunServerInvalidConfigFile(t *testing.T) { + th := SetupServerTest() + defer th.TearDownServerTest() + + // Start the server with an unreadable config file + unreadableConfigFile, err := ioutil.TempFile("", "mattermost-unreadable-config-file-") + if err != nil { + panic(err) + } + os.Chmod(unreadableConfigFile.Name(), 0200) + defer os.Remove(unreadableConfigFile.Name()) + + err = runServer(unreadableConfigFile.Name(), th.disableConfigWatch, th.interruptChan) + require.Error(t, err) +} |