diff options
author | George Goldberg <george@gberg.me> | 2018-09-17 15:51:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-17 15:51:26 +0100 |
commit | ab99f0656fabed8a62a8c6340be7d538cc7bf8d9 (patch) | |
tree | bb68ee1d0c743be23bba470f5d81ef11dc134182 /cmd/mattermost/commands/export_test.go | |
parent | 5786b0d6d57b90bbb0c262235dd9d19b497b5fae (diff) | |
download | chat-ab99f0656fabed8a62a8c6340be7d538cc7bf8d9.tar.gz chat-ab99f0656fabed8a62a8c6340be7d538cc7bf8d9.tar.bz2 chat-ab99f0656fabed8a62a8c6340be7d538cc7bf8d9.zip |
MM-11781: Basic Data Export Command Line. (#9296)
* MM-11781: Basic Data Export Command Line.
* ChannelStore new unit tests.
* TeamStore new unit tests.
* Unit test for new UserStore function.
* Unit tests for post store new methods.
* Review fixes.
* Fix duplicate command name.
Diffstat (limited to 'cmd/mattermost/commands/export_test.go')
-rw-r--r-- | cmd/mattermost/commands/export_test.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cmd/mattermost/commands/export_test.go b/cmd/mattermost/commands/export_test.go new file mode 100644 index 000000000..89ef45a6a --- /dev/null +++ b/cmd/mattermost/commands/export_test.go @@ -0,0 +1,66 @@ +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package commands + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/utils" +) + +// There are no tests that actually run the Message Export job, because it can take a long time to complete depending +// on the size of the database that the config is pointing to. As such, these tests just ensure that the CLI command +// fails fast if invalid flags are supplied + +func TestMessageExportNotEnabled(t *testing.T) { + configPath := writeTempConfig(t, false) + defer os.RemoveAll(filepath.Dir(configPath)) + + // should fail fast because the feature isn't enabled + require.Error(t, RunCommand(t, "--config", configPath, "export", "schedule")) +} + +func TestMessageExportInvalidFormat(t *testing.T) { + configPath := writeTempConfig(t, true) + defer os.RemoveAll(filepath.Dir(configPath)) + + // should fail fast because format isn't supported + require.Error(t, RunCommand(t, "--config", configPath, "--format", "not_actiance", "export", "schedule")) +} + +func TestMessageExportNegativeExportFrom(t *testing.T) { + configPath := writeTempConfig(t, true) + defer os.RemoveAll(filepath.Dir(configPath)) + + // should fail fast because export from must be a valid timestamp + require.Error(t, RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "-1", "export", "schedule")) +} + +func TestMessageExportNegativeTimeoutSeconds(t *testing.T) { + configPath := writeTempConfig(t, true) + defer os.RemoveAll(filepath.Dir(configPath)) + + // should fail fast because timeout seconds must be a positive int + require.Error(t, RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "0", "--timeoutSeconds", "-1", "export", "schedule")) +} + +func writeTempConfig(t *testing.T, isMessageExportEnabled bool) string { + dir, err := ioutil.TempDir("", "") + require.NoError(t, err) + + utils.TranslationsPreInit() + config, _, _, appErr := utils.LoadConfig("config.json") + require.Nil(t, appErr) + config.MessageExportSettings.EnableExport = model.NewBool(isMessageExportEnabled) + configPath := filepath.Join(dir, "foo.json") + require.NoError(t, ioutil.WriteFile(configPath, []byte(config.ToJson()), 0600)) + + return configPath +} |