github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/cmd/mattermost/commands/config_test.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package commands
     5  
     6  import (
     7  	"io/ioutil"
     8  	"os"
     9  	"path/filepath"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  	"github.com/stretchr/testify/require"
    14  
    15  	"github.com/mattermost/mattermost-server/model"
    16  )
    17  
    18  func TestConfigValidate(t *testing.T) {
    19  	dir, err := ioutil.TempDir("", "")
    20  	require.NoError(t, err)
    21  	defer os.RemoveAll(dir)
    22  
    23  	path := filepath.Join(dir, "config.json")
    24  	config := &model.Config{}
    25  	config.SetDefaults()
    26  	require.NoError(t, ioutil.WriteFile(path, []byte(config.ToJson()), 0600))
    27  
    28  	assert.Error(t, RunCommand(t, "--config", "foo.json", "config", "validate"))
    29  	assert.NoError(t, RunCommand(t, "--config", path, "config", "validate"))
    30  }