2023-03-15 12:00:52 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-10 21:14:03 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-15 12:00:52 -04:00
|
|
|
|
2015-03-04 02:14:54 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
|
|
import (
|
2017-09-05 00:05:41 -04:00
|
|
|
"strings"
|
2015-03-04 02:14:54 -05:00
|
|
|
"testing"
|
|
|
|
|
|
2023-12-04 14:05:02 -05:00
|
|
|
"github.com/hashicorp/cli"
|
2022-12-07 13:29:51 -05:00
|
|
|
"github.com/hashicorp/vault/version"
|
2015-03-04 02:14:54 -05:00
|
|
|
)
|
|
|
|
|
|
2017-09-05 00:05:41 -04:00
|
|
|
func testVersionCommand(tb testing.TB) (*cli.MockUi, *VersionCommand) {
|
|
|
|
|
tb.Helper()
|
|
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
|
return ui, &VersionCommand{
|
|
|
|
|
VersionInfo: &version.VersionInfo{},
|
|
|
|
|
BaseCommand: &BaseCommand{
|
|
|
|
|
UI: ui,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestVersionCommand_Run(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
t.Run("output", func(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
2018-03-28 10:34:37 -04:00
|
|
|
client, closer := testVaultServer(t)
|
|
|
|
|
defer closer()
|
|
|
|
|
|
2017-09-05 00:05:41 -04:00
|
|
|
ui, cmd := testVersionCommand(t)
|
2018-03-28 10:34:37 -04:00
|
|
|
cmd.client = client
|
|
|
|
|
|
2017-09-05 00:05:41 -04:00
|
|
|
code := cmd.Run(nil)
|
|
|
|
|
if exp := 0; code != exp {
|
|
|
|
|
t.Errorf("expected %d to be %d", code, exp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expected := "Vault"
|
|
|
|
|
combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
|
|
|
|
|
if !strings.Contains(combined, expected) {
|
|
|
|
|
t.Errorf("expected %q to equal %q", combined, expected)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("no_tabs", func(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
_, cmd := testVersionCommand(t)
|
|
|
|
|
assertNoTabs(t, cmd)
|
|
|
|
|
})
|
2015-03-04 02:14:54 -05:00
|
|
|
}
|