github.com/vnforks/kid@v5.11.1+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  	"os"
     8  	"path/filepath"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  
    13  	"github.com/mattermost/mattermost-server/utils"
    14  	"github.com/mattermost/mattermost-server/utils/fileutils"
    15  )
    16  
    17  func TestConfigFlag(t *testing.T) {
    18  	th := Setup()
    19  	defer th.TearDown()
    20  	dir := th.TemporaryDirectory()
    21  
    22  	i18n, ok := fileutils.FindDir("i18n")
    23  	require.True(t, ok)
    24  	require.NoError(t, utils.CopyDir(i18n, filepath.Join(dir, "i18n")))
    25  
    26  	prevDir, err := os.Getwd()
    27  	require.NoError(t, err)
    28  	defer os.Chdir(prevDir)
    29  	os.Chdir(dir)
    30  
    31  	t.Run("version without a config file should fail", func(t *testing.T) {
    32  		th.SetAutoConfig(false)
    33  		defer th.SetAutoConfig(true)
    34  		require.Error(t, th.RunCommand(t, "version"))
    35  	})
    36  
    37  	t.Run("version with varying paths to the config file", func(t *testing.T) {
    38  		th.CheckCommand(t, "--config", filepath.Base(th.ConfigPath()), "version")
    39  		th.CheckCommand(t, "--config", "./"+filepath.Base(th.ConfigPath()), "version")
    40  		th.CheckCommand(t, "version")
    41  	})
    42  }