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.
This commit is contained in:
Frank Schroeder 2017-05-23 01:26:30 +02:00
parent b56ffc93cb
commit 8f943542b0
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD
31 changed files with 42 additions and 42 deletions

View File

@ -259,7 +259,7 @@ func TestAgent_Reload(t *testing.T) {
ShutdownCh: shutdownCh,
Command: base.Command{
Flags: base.FlagSetNone,
UI: new(cli.MockUi),
UI: cli.NewMockUi(),
},
}

View File

@ -120,7 +120,7 @@ func TestRetryJoin(t *testing.T) {
cmd := &Command{
Version: version.Version,
ShutdownCh: shutdownCh,
Command: baseCommand(new(cli.MockUi)),
Command: baseCommand(cli.NewMockUi()),
}
serfAddr := fmt.Sprintf(
@ -181,7 +181,7 @@ func TestReadCliConfig(t *testing.T) {
"-node-meta", "somekey:somevalue",
},
ShutdownCh: shutdownCh,
Command: baseCommand(new(cli.MockUi)),
Command: baseCommand(cli.NewMockUi()),
}
config := cmd.readConfig()
@ -208,7 +208,7 @@ func TestReadCliConfig(t *testing.T) {
"-node-meta", "otherkey:othervalue",
},
ShutdownCh: shutdownCh,
Command: baseCommand(new(cli.MockUi)),
Command: baseCommand(cli.NewMockUi()),
}
expected := map[string]string{
"somekey": "somevalue",
@ -222,7 +222,7 @@ func TestReadCliConfig(t *testing.T) {
// Test LeaveOnTerm and SkipLeaveOnInt defaults for server mode
{
ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &Command{
args: []string{
"-node", `"server1"`,
@ -250,7 +250,7 @@ func TestReadCliConfig(t *testing.T) {
// Test LeaveOnTerm and SkipLeaveOnInt defaults for client mode
{
ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &Command{
args: []string{
"-data-dir", tmpDir,
@ -280,7 +280,7 @@ func TestReadCliConfig(t *testing.T) {
cmd := &Command{
args: []string{"-node", `""`},
ShutdownCh: shutdownCh,
Command: baseCommand(new(cli.MockUi)),
Command: baseCommand(cli.NewMockUi()),
}
config := cmd.readConfig()
@ -301,7 +301,7 @@ func TestRetryJoinFail(t *testing.T) {
cmd := &Command{
ShutdownCh: shutdownCh,
Command: baseCommand(new(cli.MockUi)),
Command: baseCommand(cli.NewMockUi()),
}
serfAddr := fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.Ports.SerfLan)
@ -330,7 +330,7 @@ func TestRetryJoinWanFail(t *testing.T) {
cmd := &Command{
ShutdownCh: shutdownCh,
Command: baseCommand(new(cli.MockUi)),
Command: baseCommand(cli.NewMockUi()),
}
serfAddr := fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.Ports.SerfWan)
@ -462,7 +462,7 @@ func TestProtectDataDir(t *testing.T) {
t.Fatalf("err: %v", err)
}
ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &Command{
Command: baseCommand(ui),
args: []string{"-config-file=" + cfgFile.Name()},
@ -486,7 +486,7 @@ func TestBadDataDirPermissions(t *testing.T) {
}
defer os.RemoveAll(dataDir)
ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &Command{
Command: baseCommand(ui),
args: []string{"-data-dir=" + dataDir, "-server=true"},

View File

@ -12,7 +12,7 @@ import (
)
func testConfigTestCommand(t *testing.T) (*cli.MockUi, *ConfigTestCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &ConfigTestCommand{
Command: base.Command{
UI: ui,

View File

@ -19,7 +19,7 @@ func TestEventCommandRun(t *testing.T) {
a1 := agent.NewTestAgent(t.Name(), nil)
defer a1.Shutdown()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := &EventCommand{
Command: base.Command{
UI: ui,

View File

@ -14,7 +14,7 @@ import (
)
func testExecCommand(t *testing.T) (*cli.MockUi, *ExecCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &ExecCommand{
Command: base.Command{
UI: ui,

View File

@ -13,7 +13,7 @@ import (
)
func testForceLeaveCommand(t *testing.T) (*cli.MockUi, *ForceLeaveCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &ForceLeaveCommand{
Command: base.Command{
UI: ui,
@ -68,7 +68,7 @@ func TestForceLeaveCommandRun(t *testing.T) {
func TestForceLeaveCommandRun_noAddrs(t *testing.T) {
t.Parallel()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
ui, c := testForceLeaveCommand(t)
args := []string{"-http-addr=foo"}

View File

@ -19,7 +19,7 @@ func TestInfoCommandRun(t *testing.T) {
a1 := agent.NewTestAgent(t.Name(), nil)
defer a1.Shutdown()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := &InfoCommand{
Command: base.Command{
UI: ui,

View File

@ -11,7 +11,7 @@ import (
)
func testJoinCommand(t *testing.T) (*cli.MockUi, *JoinCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &JoinCommand{
Command: base.Command{
UI: ui,

View File

@ -15,7 +15,7 @@ func TestKeygenCommand_implements(t *testing.T) {
func TestKeygenCommand(t *testing.T) {
t.Parallel()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := &KeygenCommand{
Command: base.Command{
UI: ui,

View File

@ -10,7 +10,7 @@ import (
)
func testKeyringCommand(t *testing.T) (*cli.MockUi, *KeyringCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &KeyringCommand{
Command: base.Command{
UI: ui,

View File

@ -12,7 +12,7 @@ import (
)
func testKVDeleteCommand(t *testing.T) (*cli.MockUi, *KVDeleteCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &KVDeleteCommand{
Command: base.Command{
UI: ui,

View File

@ -17,7 +17,7 @@ func TestKVExportCommand_Run(t *testing.T) {
defer a.Shutdown()
client := a.Client()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := KVExportCommand{
Command: base.Command{
UI: ui,

View File

@ -12,7 +12,7 @@ import (
)
func testKVGetCommand(t *testing.T) (*cli.MockUi, *KVGetCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &KVGetCommand{
Command: base.Command{
UI: ui,

View File

@ -28,7 +28,7 @@ func TestKVImportCommand_Run(t *testing.T) {
}
]`
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := &KVImportCommand{
Command: base.Command{
UI: ui,

View File

@ -17,7 +17,7 @@ import (
)
func testKVPutCommand(t *testing.T) (*cli.MockUi, *KVPutCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &KVPutCommand{
Command: base.Command{
UI: ui,

View File

@ -10,7 +10,7 @@ import (
)
func testLeaveCommand(t *testing.T) (*cli.MockUi, *LeaveCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &LeaveCommand{
Command: base.Command{
UI: ui,

View File

@ -15,7 +15,7 @@ import (
)
func testLockCommand(t *testing.T) (*cli.MockUi, *LockCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &LockCommand{
Command: base.Command{
UI: ui,

View File

@ -11,7 +11,7 @@ import (
)
func testMaintCommand(t *testing.T) (*cli.MockUi, *MaintCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &MaintCommand{
Command: base.Command{
UI: ui,

View File

@ -11,7 +11,7 @@ import (
)
func testMembersCommand(t *testing.T) (*cli.MockUi, *MembersCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &MembersCommand{
Command: base.Command{
UI: ui,

View File

@ -19,7 +19,7 @@ func TestOperator_Autopilot_Get(t *testing.T) {
a := agent.NewTestAgent(t.Name(), nil)
defer a.Shutdown()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := OperatorAutopilotGetCommand{
Command: base.Command{
UI: ui,

View File

@ -21,7 +21,7 @@ func TestOperator_Autopilot_Set(t *testing.T) {
a := agent.NewTestAgent(t.Name(), nil)
defer a.Shutdown()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := OperatorAutopilotSetCommand{
Command: base.Command{
UI: ui,

View File

@ -40,7 +40,7 @@ func TestOperator_Raft_ListPeers(t *testing.T) {
// Test the list-peers subcommand directly
{
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := OperatorRaftListCommand{
Command: base.Command{
UI: ui,

View File

@ -38,7 +38,7 @@ func TestOperator_Raft_RemovePeer(t *testing.T) {
// Test the remove-peer subcommand directly
{
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := OperatorRaftRemoveCommand{
Command: base.Command{
UI: ui,
@ -61,7 +61,7 @@ func TestOperator_Raft_RemovePeer(t *testing.T) {
// Test the remove-peer subcommand with -id
{
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := OperatorRaftRemoveCommand{
Command: base.Command{
UI: ui,

View File

@ -8,7 +8,7 @@ import (
)
func testOperatorRaftCommand(t *testing.T) (*cli.MockUi, *OperatorRaftCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &OperatorRaftCommand{
Command: base.Command{
UI: ui,

View File

@ -25,7 +25,7 @@ func TestReloadCommandRun(t *testing.T) {
errCh <- nil
}()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := &ReloadCommand{
Command: base.Command{
UI: ui,

View File

@ -15,7 +15,7 @@ import (
)
func testRTTCommand(t *testing.T) (*cli.MockUi, *RTTCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &RTTCommand{
Command: base.Command{
UI: ui,

View File

@ -14,7 +14,7 @@ import (
)
func testSnapshotInspectCommand(t *testing.T) (*cli.MockUi, *SnapshotInspectCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &SnapshotInspectCommand{
Command: base.Command{
UI: ui,

View File

@ -14,7 +14,7 @@ import (
)
func testSnapshotRestoreCommand(t *testing.T) (*cli.MockUi, *SnapshotRestoreCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &SnapshotRestoreCommand{
Command: base.Command{
UI: ui,

View File

@ -13,7 +13,7 @@ import (
)
func testSnapshotSaveCommand(t *testing.T) (*cli.MockUi, *SnapshotSaveCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &SnapshotSaveCommand{
Command: base.Command{
UI: ui,

View File

@ -12,7 +12,7 @@ import (
)
func testValidateCommand(t *testing.T) (*cli.MockUi, *ValidateCommand) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
return ui, &ValidateCommand{
Command: base.Command{
UI: ui,

View File

@ -19,7 +19,7 @@ func TestWatchCommandRun(t *testing.T) {
a := agent.NewTestAgent(t.Name(), nil)
defer a.Shutdown()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
c := &WatchCommand{
Command: base.Command{
UI: ui,