github.com/lologarithm/mattermost-server@v5.3.2-0.20181002060438-c82a84ed765b+incompatible/cmd/mattermost/commands/permissions_test.go (about)

     1  // Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package commands
     5  
     6  import (
     7  	"os"
     8  	"os/exec"
     9  	"strings"
    10  	"testing"
    11  
    12  	"github.com/mattermost/mattermost-server/api4"
    13  	"github.com/mattermost/mattermost-server/utils"
    14  )
    15  
    16  func TestPermissionsExport_rejectsUnlicensed(t *testing.T) {
    17  	permissionsLicenseRequiredTest(t, "export")
    18  }
    19  
    20  func TestPermissionsImport_rejectsUnlicensed(t *testing.T) {
    21  	permissionsLicenseRequiredTest(t, "import")
    22  }
    23  
    24  func permissionsLicenseRequiredTest(t *testing.T, subcommand string) {
    25  	th := api4.Setup().InitBasic()
    26  	defer th.TearDown()
    27  
    28  	path, err := os.Executable()
    29  	if err != nil {
    30  		t.Fail()
    31  	}
    32  	args := []string{"-test.run", "ExecCommand", "--", "--disableconfigwatch", "permissions", subcommand}
    33  	output, _ := exec.Command(path, args...).CombinedOutput()
    34  
    35  	actual := string(output)
    36  	expected := utils.T("cli.license.critical")
    37  	if !strings.Contains(actual, expected) {
    38  		t.Errorf("Expected '%v' but got '%v'.", expected, actual)
    39  	}
    40  }