github.com/kjdelisle/consul@v1.4.5/command/acl/bootstrap/bootstrap_test.go (about)

     1  package bootstrap
     2  
     3  import (
     4  	"os"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/consul/agent"
     9  	"github.com/hashicorp/consul/agent/structs"
    10  	"github.com/hashicorp/consul/logger"
    11  	"github.com/hashicorp/consul/testrpc"
    12  	"github.com/hashicorp/consul/testutil"
    13  	"github.com/mitchellh/cli"
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  func TestBootstrapCommand_noTabs(t *testing.T) {
    18  	t.Parallel()
    19  
    20  	if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') {
    21  		t.Fatal("help has tabs")
    22  	}
    23  }
    24  
    25  func TestBootstrapCommand(t *testing.T) {
    26  	t.Parallel()
    27  	assert := assert.New(t)
    28  
    29  	testDir := testutil.TempDir(t, "acl")
    30  	defer os.RemoveAll(testDir)
    31  
    32  	a := agent.NewTestAgent(t, t.Name(), `
    33  	primary_datacenter = "dc1"
    34  	acl {
    35  		enabled = true
    36  	}`)
    37  
    38  	a.Agent.LogWriter = logger.NewLogWriter(512)
    39  
    40  	defer a.Shutdown()
    41  	testrpc.WaitForLeader(t, a.RPC, "dc1")
    42  
    43  	ui := cli.NewMockUi()
    44  	cmd := New(ui)
    45  
    46  	args := []string{
    47  		"-http-addr=" + a.HTTPAddr(),
    48  	}
    49  
    50  	code := cmd.Run(args)
    51  	assert.Equal(code, 0)
    52  	assert.Empty(ui.ErrorWriter.String())
    53  	output := ui.OutputWriter.String()
    54  	assert.Contains(output, "Bootstrap Token")
    55  	assert.Contains(output, structs.ACLPolicyGlobalManagementID)
    56  }