github.com/spreadshirt/mattermost-server@v5.3.2-0.20180927191755-a257d501df3d+incompatible/cmd/mattermost/commands/plugin_test.go (about)

     1  package commands
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/mattermost/mattermost-server/api4"
     9  	"github.com/mattermost/mattermost-server/utils"
    10  	"github.com/stretchr/testify/assert"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestPlugin(t *testing.T) {
    15  	os.MkdirAll("./test-plugins", os.ModePerm)
    16  	os.MkdirAll("./test-client-plugins", os.ModePerm)
    17  
    18  	th := api4.Setup().InitBasic().InitSystemAdmin()
    19  	defer th.TearDown()
    20  
    21  	path, _ := utils.FindDir("tests")
    22  
    23  	os.Chdir(filepath.Join("..", "..", ".."))
    24  
    25  	CheckCommand(t, "--config", filepath.Join(path, "test-config.json"), "plugin", "add", filepath.Join(path, "testplugin.tar.gz"))
    26  
    27  	CheckCommand(t, "--config", filepath.Join(path, "test-config.json"), "plugin", "enable", "testplugin")
    28  	cfg, _, _, err := utils.LoadConfig(filepath.Join(path, "test-config.json"))
    29  	require.Nil(t, err)
    30  	assert.Equal(t, cfg.PluginSettings.PluginStates["testplugin"].Enable, true)
    31  
    32  	CheckCommand(t, "--config", filepath.Join(path, "test-config.json"), "plugin", "disable", "testplugin")
    33  	cfg, _, _, err = utils.LoadConfig(filepath.Join(path, "test-config.json"))
    34  	require.Nil(t, err)
    35  	assert.Equal(t, cfg.PluginSettings.PluginStates["testplugin"].Enable, false)
    36  
    37  	CheckCommand(t, "--config", filepath.Join(path, "test-config.json"), "plugin", "list")
    38  
    39  	CheckCommand(t, "--config", filepath.Join(path, "test-config.json"), "plugin", "delete", "testplugin")
    40  
    41  	os.Chdir(filepath.Join("cmd", "mattermost", "commands"))
    42  }