Skip to content

Commit

Permalink
Added more tests for nosql_execution_store.go (#5738)
Browse files Browse the repository at this point in the history
  • Loading branch information
agautam478 authored Mar 7, 2024
1 parent 9526e4b commit 50eedfa
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions common/persistence/nosql/nosql_execution_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,96 @@ func TestNosqlExecutionStore(t *testing.T) {
},
expectedError: &types.InternalServiceError{Message: "database error"},
},
{
name: "ListConcreteExecutions success - has executions",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
// Corrected return value type to match expected method signature
executions := []*persistence.InternalListConcreteExecutionsEntity{
{
ExecutionInfo: &persistence.InternalWorkflowExecutionInfo{
WorkflowID: "workflowID",
RunID: "runID",
},
},
}
mockDB.EXPECT().
SelectAllWorkflowExecutions(ctx, shardID, gomock.Any(), gomock.Any()).
Return(executions, nil, nil)
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
resp, err := store.ListConcreteExecutions(ctx, &persistence.ListConcreteExecutionsRequest{})
if err != nil {
return err
}
if len(resp.Executions) == 0 {
return errors.New("expected to find executions")
}
return nil
},
expectedError: nil,
},
{
name: "ListConcreteExecutions failure - database error",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
mockDB.EXPECT().
SelectAllWorkflowExecutions(ctx, shardID, gomock.Any(), gomock.Any()).
Return(nil, nil, errors.New("database error"))
mockDB.EXPECT().IsNotFoundError(gomock.Any()).Return(true).AnyTimes()
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
_, err := store.ListConcreteExecutions(ctx, &persistence.ListConcreteExecutionsRequest{})
return err
},
expectedError: &types.InternalServiceError{Message: "database error"},
},
{
name: "GetTransferTasks success - has tasks",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
tasks := []*nosqlplugin.TransferTask{{TaskID: 1}}
mockDB.EXPECT().
SelectTransferTasksOrderByTaskID(ctx, shardID, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(tasks, nil, nil)
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
resp, err := store.GetTransferTasks(ctx, &persistence.GetTransferTasksRequest{})
if err != nil {
return err
}
if len(resp.Tasks) == 0 {
return errors.New("expected to find transfer tasks")
}
return nil
},
expectedError: nil,
},
{
name: "GetCrossClusterTasks success - has tasks",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
tasks := []*nosqlplugin.CrossClusterTask{{TransferTask: persistence.CrossClusterTaskInfo{TaskID: 1}}}
mockDB.EXPECT().
SelectCrossClusterTasksOrderByTaskID(ctx, shardID, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(tasks, nil, nil)
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
resp, err := store.GetCrossClusterTasks(ctx, &persistence.GetCrossClusterTasksRequest{})
if err != nil {
return err
}
if len(resp.Tasks) == 0 {
return errors.New("expected to find cross cluster tasks")
}
return nil
},
expectedError: nil,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 50eedfa

Please sign in to comment.