2023-03-28 19:12:30 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 19:12:30 +00:00
|
|
|
|
2017-10-11 12:51:25 +00:00
|
|
|
package keygen
|
2013-12-31 21:06:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
2017-10-11 12:51:25 +00:00
|
|
|
"strings"
|
2017-05-12 13:41:13 +00:00
|
|
|
"testing"
|
|
|
|
|
2013-12-31 21:06:33 +00:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
2017-10-11 12:51:25 +00:00
|
|
|
func TestKeygenCommand_noTabs(t *testing.T) {
|
2017-10-17 14:07:48 +00:00
|
|
|
t.Parallel()
|
2017-10-11 12:51:25 +00:00
|
|
|
if strings.ContainsRune(New(nil).Help(), '\t') {
|
2017-10-17 13:44:20 +00:00
|
|
|
t.Fatal("help has tabs")
|
2017-10-11 12:51:25 +00:00
|
|
|
}
|
2013-12-31 21:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestKeygenCommand(t *testing.T) {
|
2017-10-17 14:07:48 +00:00
|
|
|
t.Parallel()
|
2017-05-22 23:26:30 +00:00
|
|
|
ui := cli.NewMockUi()
|
2017-10-11 12:51:25 +00:00
|
|
|
cmd := New(ui)
|
|
|
|
code := cmd.Run(nil)
|
2013-12-31 21:06:33 +00:00
|
|
|
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)
|
|
|
|
}
|
2019-07-30 15:45:41 +00:00
|
|
|
if len(result) != 32 {
|
2013-12-31 21:06:33 +00:00
|
|
|
t.Fatalf("bad: %#v", result)
|
|
|
|
}
|
|
|
|
}
|