github.com/jfrerich/mattermost-server@v5.8.0-rc2+incompatible/cmd/mattermost/commands/config_flag_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package commands 5 6 import ( 7 "encoding/json" 8 "io/ioutil" 9 "os" 10 "path/filepath" 11 "testing" 12 13 "github.com/stretchr/testify/require" 14 15 "github.com/mattermost/mattermost-server/utils" 16 "github.com/mattermost/mattermost-server/utils/fileutils" 17 ) 18 19 func TestConfigFlag(t *testing.T) { 20 th := Setup() 21 defer th.TearDown() 22 dir := th.TemporaryDirectory() 23 24 timezones := th.App.Timezones.GetSupported() 25 tzConfigPath := filepath.Join(dir, "timezones.json") 26 timezoneData, _ := json.Marshal(timezones) 27 require.NoError(t, ioutil.WriteFile(tzConfigPath, timezoneData, 0600)) 28 29 i18n, ok := fileutils.FindDir("i18n") 30 require.True(t, ok) 31 require.NoError(t, utils.CopyDir(i18n, filepath.Join(dir, "i18n"))) 32 33 prevDir, err := os.Getwd() 34 require.NoError(t, err) 35 defer os.Chdir(prevDir) 36 os.Chdir(dir) 37 38 t.Run("version without a config file should fail", func(t *testing.T) { 39 th.SetAutoConfig(false) 40 defer th.SetAutoConfig(true) 41 require.Error(t, th.RunCommand(t, "version")) 42 }) 43 44 t.Run("version with varying paths to the config file", func(t *testing.T) { 45 th.CheckCommand(t, "--config", filepath.Base(th.ConfigPath()), "version") 46 th.CheckCommand(t, "--config", "./"+filepath.Base(th.ConfigPath()), "version") 47 th.CheckCommand(t, "version") 48 }) 49 }