Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: move tests to use NewMockUi func. #9027

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions command/acl_bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestACLBootstrapCommand(t *testing.T) {

assert.Nil(srv.RootToken)

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLBootstrapCommand{Meta: Meta{Ui: ui, flagAddress: url}}

code := cmd.Run([]string{"-address=" + url})
Expand All @@ -48,7 +48,7 @@ func TestACLBootstrapCommand_ExistingBootstrapToken(t *testing.T) {

assert.NotNil(srv.RootToken)

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLBootstrapCommand{Meta: Meta{Ui: ui, flagAddress: url}}

code := cmd.Run([]string{"-address=" + url})
Expand All @@ -66,7 +66,7 @@ func TestACLBootstrapCommand_NonACLServer(t *testing.T) {
srv, _, url := testServer(t, true, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLBootstrapCommand{Meta: Meta{Ui: ui, flagAddress: url}}

code := cmd.Run([]string{"-address=" + url})
Expand Down
2 changes: 1 addition & 1 deletion command/acl_policy_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestACLPolicyApplyCommand(t *testing.T) {
token := srv.RootToken
assert.NotNil(token, "failed to bootstrap ACL token")

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLPolicyApplyCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a test policy
Expand Down
2 changes: 1 addition & 1 deletion command/acl_policy_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestACLPolicyDeleteCommand(t *testing.T) {
policy.SetHash()
assert.Nil(state.UpsertACLPolicies(1000, []*structs.ACLPolicy{policy}))

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLPolicyDeleteCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Delete the policy without a valid token fails
Expand Down
2 changes: 1 addition & 1 deletion command/acl_policy_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestACLPolicyInfoCommand(t *testing.T) {
policy.SetHash()
assert.Nil(state.UpsertACLPolicies(1000, []*structs.ACLPolicy{policy}))

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLPolicyInfoCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Attempt to apply a policy without a valid management token
Expand Down
2 changes: 1 addition & 1 deletion command/acl_policy_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestACLPolicyListCommand(t *testing.T) {
policy.SetHash()
assert.Nil(state.UpsertACLPolicies(1000, []*structs.ACLPolicy{policy}))

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLPolicyListCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Attempt to list policies without a valid management token
Expand Down
2 changes: 1 addition & 1 deletion command/acl_token_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestACLTokenCreateCommand(t *testing.T) {
token := srv.RootToken
assert.NotNil(token, "failed to bootstrap ACL token")

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLTokenCreateCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Request to create a new token without providing a valid management token
Expand Down
2 changes: 1 addition & 1 deletion command/acl_token_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestACLTokenDeleteCommand_ViaEnvVariable(t *testing.T) {
token := srv.RootToken
assert.NotNil(token, "failed to bootstrap ACL token")

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLTokenDeleteCommand{Meta: Meta{Ui: ui, flagAddress: url}}
state := srv.Agent.Server().State()

Expand Down
2 changes: 1 addition & 1 deletion command/acl_token_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestACLTokenInfoCommand_ViaEnvVar(t *testing.T) {
token := srv.RootToken
assert.NotNil(token, "failed to bootstrap ACL token")

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLTokenInfoCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a valid token
Expand Down
2 changes: 1 addition & 1 deletion command/acl_token_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestACLTokenListCommand(t *testing.T) {
mockToken.SetHash()
assert.Nil(state.UpsertACLTokens(1000, []*structs.ACLToken{mockToken}))

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLTokenListCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Attempt to list tokens without a valid management token
Expand Down
2 changes: 1 addition & 1 deletion command/acl_token_self_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestACLTokenSelfCommand_ViaEnvVar(t *testing.T) {
token := srv.RootToken
assert.NotNil(token, "failed to bootstrap ACL token")

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLTokenSelfCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a valid token
Expand Down
2 changes: 1 addition & 1 deletion command/acl_token_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestACLTokenUpdateCommand(t *testing.T) {
token := srv.RootToken
assert.NotNil(token, "failed to bootstrap ACL token")

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &ACLTokenUpdateCommand{Meta: Meta{Ui: ui, flagAddress: url}}
state := srv.Agent.Server().State()

Expand Down
4 changes: 2 additions & 2 deletions command/agent/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestCommand_Args(t *testing.T) {
for _, tc := range tcases {
// Make a new command. We preemptively close the shutdownCh
// so that the command exits immediately instead of blocking.
ui := new(cli.MockUi)
ui := cli.NewMockUi()
shutdownCh := make(chan struct{})
close(shutdownCh)
cmd := &Command{
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestCommand_MetaConfigValidation(t *testing.T) {

// Make a new command. We preemptively close the shutdownCh
// so that the command exits immediately instead of blocking.
ui := new(cli.MockUi)
ui := cli.NewMockUi()
shutdownCh := make(chan struct{})
close(shutdownCh)
cmd := &Command{
Expand Down
4 changes: 2 additions & 2 deletions command/agent_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAgentInfoCommand_Run(t *testing.T) {
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}

code := cmd.Run([]string{"-address=" + url})
Expand All @@ -28,7 +28,7 @@ func TestAgentInfoCommand_Run(t *testing.T) {

func TestAgentInfoCommand_Fails(t *testing.T) {
t.Parallel()
ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}

// Fails on misuse
Expand Down
2 changes: 1 addition & 1 deletion command/agent_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestMonitorCommand_Fails(t *testing.T) {
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &MonitorCommand{Meta: Meta{Ui: ui}}

// Fails on misuse
Expand Down
12 changes: 6 additions & 6 deletions command/alloc_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestAllocExecCommand_Fails(t *testing.T) {

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocExecCommand{Meta: Meta{Ui: ui}}

code := cmd.Run(c.args)
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestAllocExecCommand_Fails(t *testing.T) {
})

t.Run("non existent task", func(t *testing.T) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocExecCommand{Meta: Meta{Ui: ui}}

jobID := "job1_sfx"
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestAllocExecCommand_AutocompleteArgs(t *testing.T) {
srv, _, url := testServer(t, true, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocExecCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a fake alloc
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestAllocExecCommand_Run(t *testing.T) {
resp, _, err := client.Jobs().Register(job, nil)
require.NoError(t, err)

evalUi := new(cli.MockUi)
evalUi := cli.NewMockUi()
code := waitForSuccess(evalUi, client, fullId, t, resp.EvalID)
require.Equal(t, 0, code, "failed to get status - output: %v", evalUi.ErrorWriter.String())

Expand Down Expand Up @@ -249,7 +249,7 @@ func TestAllocExecCommand_Run(t *testing.T) {

for _, c := range cases {
t.Run("by id: "+c.name, func(t *testing.T) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
var stdout, stderr bufferCloser

cmd := &AllocExecCommand{
Expand All @@ -265,7 +265,7 @@ func TestAllocExecCommand_Run(t *testing.T) {
assert.Equal(t, c.stderr, strings.TrimSpace(stderr.String()))
})
t.Run("by job: "+c.name, func(t *testing.T) {
ui := new(cli.MockUi)
ui := cli.NewMockUi()
var stdout, stderr bufferCloser

cmd := &AllocExecCommand{
Expand Down
4 changes: 2 additions & 2 deletions command/alloc_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestFSCommand_Fails(t *testing.T) {
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocFSCommand{Meta: Meta{Ui: ui}}

// Fails on lack of job ID
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestFSCommand_AutocompleteArgs(t *testing.T) {
srv, _, url := testServer(t, true, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocFSCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a fake alloc
Expand Down
4 changes: 2 additions & 2 deletions command/alloc_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestLogsCommand_Fails(t *testing.T) {
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocLogsCommand{Meta: Meta{Ui: ui}}

// Fails on misuse
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestLogsCommand_AutocompleteArgs(t *testing.T) {
srv, _, url := testServer(t, true, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocLogsCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a fake alloc
Expand Down
6 changes: 3 additions & 3 deletions command/alloc_restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAllocRestartCommand_Fails(t *testing.T) {
defer srv.Shutdown()

require := require.New(t)
ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocRestartCommand{Meta: Meta{Ui: ui}}

// Fails on misuse
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestAllocRestartCommand_Run(t *testing.T) {
t.Fatalf("err: %v", err)
})

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocRestartCommand{Meta: Meta{Ui: ui}}

jobID := "job1_sfx"
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestAllocRestartCommand_AutocompleteArgs(t *testing.T) {
srv, _, url := testServer(t, true, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocRestartCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a fake alloc
Expand Down
6 changes: 3 additions & 3 deletions command/alloc_signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAllocSignalCommand_Fails(t *testing.T) {

require := require.New(t)

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocSignalCommand{Meta: Meta{Ui: ui}}

// Fails on lack of alloc ID
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestAllocSignalCommand_AutocompleteArgs(t *testing.T) {
srv, _, url := testServer(t, true, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocSignalCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a fake alloc
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestAllocSignalCommand_Run(t *testing.T) {
t.Fatalf("err: %v", err)
})

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocSignalCommand{Meta: Meta{Ui: ui}}

jobID := "job1_sfx"
Expand Down
16 changes: 8 additions & 8 deletions command/alloc_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAllocStatusCommand_Fails(t *testing.T) {
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}

// Fails on misuse
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestAllocStatusCommand_LifecycleInfo(t *testing.T) {
require.NoError(t, err)
})

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
state := srv.Agent.Server().State()

Expand Down Expand Up @@ -172,7 +172,7 @@ func TestAllocStatusCommand_Run(t *testing.T) {
t.Fatalf("err: %v", err)
})

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}

jobID := "job1_sfx"
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestAllocStatusCommand_RescheduleInfo(t *testing.T) {
t.Fatalf("err: %v", err)
})

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
// Test reschedule attempt info
require := require.New(t)
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestAllocStatusCommand_ScoreMetrics(t *testing.T) {
t.Fatalf("err: %v", err)
})

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
// Test node metrics
require := require.New(t)
Expand Down Expand Up @@ -365,7 +365,7 @@ func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) {
srv, _, url := testServer(t, true, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a fake alloc
Expand Down Expand Up @@ -439,7 +439,7 @@ func TestAllocStatusCommand_HostVolumes(t *testing.T) {
require.NoError(t, state.UpsertJobSummary(1004, summary))
require.NoError(t, state.UpsertAllocs(1005, []*structs.Allocation{alloc}))

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
if code := cmd.Run([]string{"-address=" + url, "-verbose", alloc.ID}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
Expand Down Expand Up @@ -514,7 +514,7 @@ func TestAllocStatusCommand_CSIVolumes(t *testing.T) {
require.NoError(t, state.UpsertJobSummary(1004, summary))
require.NoError(t, state.UpsertAllocs(1005, []*structs.Allocation{alloc}))

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
if code := cmd.Run([]string{"-address=" + url, "-verbose", alloc.ID}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
Expand Down
4 changes: 2 additions & 2 deletions command/alloc_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAllocStop_Fails(t *testing.T) {
defer srv.Shutdown()

require := require.New(t)
ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStopCommand{Meta: Meta{Ui: ui}}

// Fails on misuse
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestAllocStop_Run(t *testing.T) {
t.Fatalf("err: %v", err)
})

ui := new(cli.MockUi)
ui := cli.NewMockUi()
cmd := &AllocStopCommand{Meta: Meta{Ui: ui}}

jobID := "job1_sfx"
Expand Down
Loading