github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/cmd/platform/mattermost_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package main 5 6 import ( 7 "io/ioutil" 8 "os" 9 "path/filepath" 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 14 "github.com/mattermost/mattermost-server/utils" 15 ) 16 17 func TestConfigFlag(t *testing.T) { 18 dir, err := ioutil.TempDir("", "") 19 require.NoError(t, err) 20 defer os.RemoveAll(dir) 21 22 utils.TranslationsPreInit() 23 config, _, err := utils.LoadConfig("config.json") 24 require.Nil(t, err) 25 configPath := filepath.Join(dir, "foo.json") 26 require.NoError(t, ioutil.WriteFile(configPath, []byte(config.ToJson()), 0600)) 27 28 i18n, ok := utils.FindDir("i18n") 29 require.True(t, ok) 30 require.NoError(t, utils.CopyDir(i18n, filepath.Join(dir, "i18n"))) 31 32 prevDir, err := os.Getwd() 33 require.NoError(t, err) 34 defer os.Chdir(prevDir) 35 os.Chdir(dir) 36 37 require.Error(t, runCommand(t, "version")) 38 checkCommand(t, "--config", "foo.json", "version") 39 checkCommand(t, "--config", "./foo.json", "version") 40 checkCommand(t, "--config", configPath, "version") 41 }