open-consul/command/keygen_test.go
Frank Schroeder 846fe5d630
test: use cli.NewMockUi instead of new(cli.MockUi)
Use the constructor function to prevent a nil panic
if there was no write to the output buffers.
2017-05-31 00:29:26 +02:00

40 lines
678 B
Go

package command
import (
"encoding/base64"
"testing"
"github.com/hashicorp/consul/command/base"
"github.com/mitchellh/cli"
)
func TestKeygenCommand_implements(t *testing.T) {
t.Parallel()
var _ cli.Command = &KeygenCommand{}
}
func TestKeygenCommand(t *testing.T) {
t.Parallel()
ui := cli.NewMockUi()
c := &KeygenCommand{
Command: base.Command{
UI: ui,
Flags: base.FlagSetNone,
},
}
code := c.Run(nil)
if code != 0 {
t.Fatalf("bad: %d", code)
}
output := ui.OutputWriter.String()
result, err := base64.StdEncoding.DecodeString(output)
if err != nil {
t.Fatalf("err: %s", err)
}
if len(result) != 16 {
t.Fatalf("bad: %#v", result)
}
}