github.com/rajatvaryani/mattermost-server@v5.11.1+incompatible/cmd/mattermost/commands/export_test.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package commands 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 11 "github.com/mattermost/mattermost-server/model" 12 ) 13 14 // There are no tests that actually run the Message Export job, because it can take a long time to complete depending 15 // on the size of the database that the config is pointing to. As such, these tests just ensure that the CLI command 16 // fails fast if invalid flags are supplied 17 18 func TestMessageExportNotEnabled(t *testing.T) { 19 th := Setup() 20 defer th.TearDown() 21 22 config := th.Config() 23 config.MessageExportSettings.EnableExport = model.NewBool(false) 24 th.SetConfig(config) 25 26 // should fail fast because the feature isn't enabled 27 require.Error(t, th.RunCommand(t, "export", "schedule")) 28 } 29 30 func TestMessageExportInvalidFormat(t *testing.T) { 31 th := Setup() 32 defer th.TearDown() 33 34 config := th.Config() 35 config.MessageExportSettings.EnableExport = model.NewBool(true) 36 th.SetConfig(config) 37 38 // should fail fast because format isn't supported 39 require.Error(t, th.RunCommand(t, "--format", "not_actiance", "export", "schedule")) 40 } 41 42 func TestMessageExportNegativeExportFrom(t *testing.T) { 43 th := Setup() 44 defer th.TearDown() 45 46 config := th.Config() 47 config.MessageExportSettings.EnableExport = model.NewBool(true) 48 th.SetConfig(config) 49 50 // should fail fast because export from must be a valid timestamp 51 require.Error(t, th.RunCommand(t, "--format", "actiance", "--exportFrom", "-1", "export", "schedule")) 52 } 53 54 func TestMessageExportNegativeTimeoutSeconds(t *testing.T) { 55 th := Setup() 56 defer th.TearDown() 57 58 config := th.Config() 59 config.MessageExportSettings.EnableExport = model.NewBool(true) 60 th.SetConfig(config) 61 62 // should fail fast because timeout seconds must be a positive int 63 require.Error(t, th.RunCommand(t, "--format", "actiance", "--exportFrom", "0", "--timeoutSeconds", "-1", "export", "schedule")) 64 }