github.com/spline-fu/mattermost-server@v4.10.10+incompatible/cmd/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/mattermost/mattermost-server/cmd"
    13  	"github.com/stretchr/testify/assert"
    14  	"github.com/stretchr/testify/require"
    15  
    16  	"github.com/mattermost/mattermost-server/model"
    17  )
    18  
    19  func TestConfigValidate(t *testing.T) {
    20  	dir, err := ioutil.TempDir("", "")
    21  	require.NoError(t, err)
    22  	defer os.RemoveAll(dir)
    23  
    24  	path := filepath.Join(dir, "config.json")
    25  	config := &model.Config{}
    26  	config.SetDefaults()
    27  	require.NoError(t, ioutil.WriteFile(path, []byte(config.ToJson()), 0600))
    28  
    29  	assert.Error(t, cmd.RunCommand(t, "--config", "foo.json", "config", "validate"))
    30  	assert.NoError(t, cmd.RunCommand(t, "--config", path, "config", "validate"))
    31  }