command/keys: begin tests

This commit is contained in:
Ryan Uber 2014-09-10 08:49:16 -07:00
parent 46ce9e936f
commit 90de483871
3 changed files with 44 additions and 0 deletions

View File

@ -665,6 +665,10 @@ func (i *AgentRPC) handleGossipKeyChange(client *rpcClient, seq uint64, cmd stri
queryResp, err = i.agent.RemoveKeyWAN(req.Key) queryResp, err = i.agent.RemoveKeyWAN(req.Key)
case removeKeyLANCommand: case removeKeyLANCommand:
queryResp, err = i.agent.RemoveKeyLAN(req.Key) 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{ header := responseHeader{

33
command/keys_test.go Normal file
View File

@ -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())
}
}

View File

@ -39,6 +39,10 @@ func (a *agentWrapper) Shutdown() {
} }
func testAgent(t *testing.T) *agentWrapper { 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") l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
@ -48,6 +52,9 @@ func testAgent(t *testing.T) *agentWrapper {
mult := io.MultiWriter(os.Stderr, lw) mult := io.MultiWriter(os.Stderr, lw)
conf := nextConfig() conf := nextConfig()
if c != nil {
conf = agent.MergeConfig(conf, c)
}
dir, err := ioutil.TempDir("", "agent") dir, err := ioutil.TempDir("", "agent")
if err != nil { if err != nil {