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, ShutdownCh: shutdownCh,
Command: base.Command{ Command: base.Command{
Flags: base.FlagSetNone, Flags: base.FlagSetNone,
UI: new(cli.MockUi), UI: cli.NewMockUi(),
}, },
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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