github.com/DerekStrickland/consul@v1.4.5/command/connect/ca/set/connect_ca_set_test.go (about) 1 package set 2 3 import ( 4 "strings" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/require" 9 10 "github.com/hashicorp/consul/agent" 11 "github.com/hashicorp/consul/agent/connect/ca" 12 "github.com/hashicorp/consul/agent/structs" 13 "github.com/hashicorp/consul/testrpc" 14 "github.com/mitchellh/cli" 15 ) 16 17 func TestConnectCASetConfigCommand_noTabs(t *testing.T) { 18 t.Parallel() 19 if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') { 20 t.Fatal("help has tabs") 21 } 22 } 23 24 func TestConnectCASetConfigCommand(t *testing.T) { 25 t.Parallel() 26 require := require.New(t) 27 a := agent.NewTestAgent(t, t.Name(), ``) 28 defer a.Shutdown() 29 30 testrpc.WaitForTestAgent(t, a.RPC, "dc1") 31 ui := cli.NewMockUi() 32 c := New(ui) 33 args := []string{ 34 "-http-addr=" + a.HTTPAddr(), 35 "-config-file=test-fixtures/ca_config.json", 36 } 37 38 code := c.Run(args) 39 if code != 0 { 40 t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) 41 } 42 43 req := structs.DCSpecificRequest{ 44 Datacenter: "dc1", 45 } 46 var reply structs.CAConfiguration 47 require.NoError(a.RPC("ConnectCA.ConfigurationGet", &req, &reply)) 48 require.Equal("consul", reply.Provider) 49 50 parsed, err := ca.ParseConsulCAConfig(reply.Config) 51 require.NoError(err) 52 require.Equal(24*time.Hour, parsed.RotationPeriod) 53 }