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