github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/cmd/hkserver/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 "os" 8 "path/filepath" 9 "testing" 10 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestConfigFlag(t *testing.T) { 15 th := Setup(t) 16 defer th.TearDown() 17 dir := th.TemporaryDirectory() 18 19 prevDir, err := os.Getwd() 20 require.NoError(t, err) 21 defer os.Chdir(prevDir) 22 os.Chdir(dir) 23 24 t.Run("version without a config file should fail", func(t *testing.T) { 25 err := os.RemoveAll("config") 26 require.NoError(t, err) 27 th.SetAutoConfig(false) 28 defer th.SetAutoConfig(true) 29 require.Error(t, th.RunCommand(t, "version")) 30 }) 31 32 t.Run("version with varying paths to the config file", func(t *testing.T) { 33 th.CheckCommand(t, "--config", filepath.Base(th.ConfigPath()), "version") 34 th.CheckCommand(t, "--config", "./"+filepath.Base(th.ConfigPath()), "version") 35 th.CheckCommand(t, "version") 36 }) 37 }