open-vault/command/version_test.go

54 lines
996 B
Go
Raw Normal View History

2015-03-04 07:14:54 +00:00
package command
import (
2017-09-05 04:05:41 +00:00
"strings"
2015-03-04 07:14:54 +00:00
"testing"
"github.com/hashicorp/vault/version"
2015-03-04 07:14:54 +00:00
"github.com/mitchellh/cli"
)
2017-09-05 04:05:41 +00: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()
client, closer := testVaultServer(t)
defer closer()
2017-09-05 04:05:41 +00:00
ui, cmd := testVersionCommand(t)
cmd.client = client
2017-09-05 04:05:41 +00: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 07:14:54 +00:00
}