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

Add test coverage to admin tasklist commands #6390

Merged
Merged
Changes from 1 commit
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
105 changes: 105 additions & 0 deletions tools/cli/admin_task_list_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,111 @@ func TestAdminDescribeTaskList_InvalidTaskListType(t *testing.T) {
assert.NoError(t, err)
}

func TestAdminListTaskList_Success(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

// Mock clients
serverFrontendClient := frontend.NewMockClient(mockCtrl)
serverAdminClient := admin.NewMockClient(mockCtrl)

// Create CLI app with mock clients
app := NewCliApp(&clientFactoryMock{
serverFrontendClient: serverFrontendClient,
serverAdminClient: serverAdminClient,
})

// Prepare expected response
expectedResponse := &types.GetTaskListsByDomainResponse{
DecisionTaskListMap: map[string]*types.DescribeTaskListResponse{
"decision-tasklist-1": {
Pollers: []*types.PollerInfo{
{Identity: "poller1"},
{Identity: "poller2"},
},
},
"decision-tasklist-2": {
Pollers: []*types.PollerInfo{
{Identity: "poller3"},
},
},
},
ActivityTaskListMap: map[string]*types.DescribeTaskListResponse{
"activity-tasklist-1": {
Pollers: []*types.PollerInfo{
{Identity: "poller4"},
},
},
},
}

// Set up the expected call and response
serverFrontendClient.EXPECT().
GetTaskListsByDomain(gomock.Any(), gomock.Any()).
Return(expectedResponse, nil).
Times(1)

// Set up CLI context
c := setTasklistMock(app)

// Call the function under test
err := AdminListTaskList(c)
assert.NoError(t, err)
}

func TestAdminListTaskList_GetTaskListsByDomainFails(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

// Mock clients
serverFrontendClient := frontend.NewMockClient(mockCtrl)
serverAdminClient := admin.NewMockClient(mockCtrl)

// Create CLI app with mock clients
app := NewCliApp(&clientFactoryMock{
serverFrontendClient: serverFrontendClient,
serverAdminClient: serverAdminClient,
})

// Set up the expected call to return an error
serverFrontendClient.EXPECT().
GetTaskListsByDomain(gomock.Any(), gomock.Any()).
Return(nil, fmt.Errorf("GetTaskListsByDomain failed")).
Times(1)

// Set up CLI context
c := setTasklistMock(app)

// Call the function under test
err := AdminListTaskList(c)
assert.Error(t, err)
assert.Contains(t, err.Error(), "Operation GetTaskListByDomain failed.")
}

func TestAdminListTaskList_NoDomainFlag(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

// Mock clients
serverFrontendClient := frontend.NewMockClient(mockCtrl)
serverAdminClient := admin.NewMockClient(mockCtrl)

// Create CLI app with mock clients
app := NewCliApp(&clientFactoryMock{
serverFrontendClient: serverFrontendClient,
serverAdminClient: serverAdminClient,
})

// Omit the Domain flag
set := flag.NewFlagSet("test", 0)
c := cli.NewContext(app, set, nil)

// Call the function under test
err := AdminListTaskList(c)
assert.Error(t, err)
assert.Contains(t, err.Error(), "Required flag not found: ")
}

// Helper function to set up the CLI context
func setTasklistMock(app *cli.App) *cli.Context {
set := flag.NewFlagSet("test", 0)
Expand Down
Loading