command/keys: begin tests
This commit is contained in:
parent
5f04ae277e
commit
109a3604da
|
@ -665,6 +665,10 @@ func (i *AgentRPC) handleGossipKeyChange(client *rpcClient, seq uint64, cmd stri
|
|||
queryResp, err = i.agent.RemoveKeyWAN(req.Key)
|
||||
case removeKeyLANCommand:
|
||||
queryResp, err = i.agent.RemoveKeyLAN(req.Key)
|
||||
default:
|
||||
respHeader := responseHeader{Seq: seq, Error: unsupportedCommand}
|
||||
client.Send(&respHeader, nil)
|
||||
return fmt.Errorf("command '%s' not recognized", cmd)
|
||||
}
|
||||
|
||||
header := responseHeader{
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/consul/command/agent"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func TestKeysCommand_implements(t *testing.T) {
|
||||
var _ cli.Command = &KeysCommand{}
|
||||
}
|
||||
|
||||
func TestKeysCommand_list(t *testing.T) {
|
||||
conf := agent.Config{EncryptKey: "HS5lJ+XuTlYKWaeGYyG+/A=="}
|
||||
|
||||
a1 := testAgentWithConfig(&conf, t)
|
||||
defer a1.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
c := &KeysCommand{Ui: ui}
|
||||
args := []string{"-list", "-rpc-addr=" + a1.addr}
|
||||
|
||||
code := c.Run(args)
|
||||
if code != 0 {
|
||||
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
if !strings.Contains(ui.OutputWriter.String(), conf.EncryptKey) {
|
||||
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
||||
}
|
||||
}
|
|
@ -39,6 +39,10 @@ func (a *agentWrapper) Shutdown() {
|
|||
}
|
||||
|
||||
func testAgent(t *testing.T) *agentWrapper {
|
||||
return testAgentWithConfig(nil, t)
|
||||
}
|
||||
|
||||
func testAgentWithConfig(c *agent.Config, t *testing.T) *agentWrapper {
|
||||
l, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
@ -48,6 +52,9 @@ func testAgent(t *testing.T) *agentWrapper {
|
|||
mult := io.MultiWriter(os.Stderr, lw)
|
||||
|
||||
conf := nextConfig()
|
||||
if c != nil {
|
||||
conf = agent.MergeConfig(conf, c)
|
||||
}
|
||||
|
||||
dir, err := ioutil.TempDir("", "agent")
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue