Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelreiswildlife committed Jun 28, 2024
1 parent 4e1a2a0 commit 2136d07
Showing 1 changed file with 6 additions and 54 deletions.
60 changes: 6 additions & 54 deletions internal/core/operations/rooms/remove/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestExecutor_Execute(t *testing.T) {
})

t.Run("should succeed - rooms are successfully removed => returns without error", func(t *testing.T) {
executor, roomsStorage, roomsManager, _ := testSetup(t)
executor, _, roomsManager, _ := testSetup(t)

firstRoomID := "first-room-id"
secondRoomID := "second-room-id"
Expand All @@ -163,48 +163,20 @@ func TestExecutor_Execute(t *testing.T) {
room := &game_room.GameRoom{
ID: firstRoomID,
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
Metadata: map[string]interface{}{},
}
secondRoom := &game_room.GameRoom{
ID: secondRoomID,
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
Metadata: map[string]interface{}{},
}
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, firstRoomID).Return(room, nil)
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, secondRoomID).Return(secondRoom, nil)
roomsManager.EXPECT().DeleteRoom(gomock.Any(), room).Return(nil)
roomsManager.EXPECT().DeleteRoom(gomock.Any(), secondRoom).Return(nil)

err := executor.Execute(context.Background(), op, definition)
require.Nil(t, err)
})

t.Run("when failed to get any room it returns with error", func(t *testing.T) {
executor, roomsStorage, _, _ := testSetup(t)

firstRoomID := "first-room-id"
secondRoomID := "second-room-id"

schedulerName := uuid.NewString()
definition := &Definition{RoomsIDs: []string{firstRoomID, secondRoomID}}
op := &operation.Operation{ID: "random-uuid", SchedulerName: schedulerName}

room := &game_room.GameRoom{
ID: firstRoomID,
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
}
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, firstRoomID).Return(room, nil)
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, secondRoomID).Return(nil, fmt.Errorf("error on GetRoom"))

err := executor.Execute(context.Background(), op, definition)
require.ErrorContains(t, err, "error removing rooms by ids: error on GetRoom")
})

t.Run("when any room failed to delete with unexpected error it returns with error", func(t *testing.T) {
executor, roomsStorage, roomsManager, operationManager := testSetup(t)
executor, _, roomsManager, operationManager := testSetup(t)

firstRoomID := "first-room-id"
secondRoomID := "second-room-id"
Expand All @@ -216,17 +188,13 @@ func TestExecutor_Execute(t *testing.T) {
room := &game_room.GameRoom{
ID: firstRoomID,
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
}
secondRoom := &game_room.GameRoom{
ID: firstRoomID,
ID: secondRoomID,
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
}
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, firstRoomID).Return(room, nil)
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, secondRoomID).Return(secondRoom, nil)
roomsManager.EXPECT().DeleteRoom(gomock.Any(), room).Return(nil)

roomsManager.EXPECT().DeleteRoom(gomock.Any(), room).Return(nil)
roomsManager.EXPECT().DeleteRoom(gomock.Any(), secondRoom).Return(fmt.Errorf("error on remove room"))
operationManager.EXPECT().AppendOperationEventToExecutionHistory(gomock.Any(), op, gomock.Any())

Expand All @@ -235,7 +203,7 @@ func TestExecutor_Execute(t *testing.T) {
})

t.Run("when any room failed to delete with timeout error it returns with error", func(t *testing.T) {
executor, roomsStorage, roomsManager, operationManager := testSetup(t)
executor, _, roomsManager, operationManager := testSetup(t)

firstRoomID := "first-room-id"
secondRoomID := "second-room-id"
Expand All @@ -247,15 +215,11 @@ func TestExecutor_Execute(t *testing.T) {
room := &game_room.GameRoom{
ID: firstRoomID,
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
}
secondRoom := &game_room.GameRoom{
ID: secondRoomID,
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
}
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, firstRoomID).Return(room, nil)
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, secondRoomID).Return(secondRoom, nil)
roomsManager.EXPECT().DeleteRoom(gomock.Any(), room).Return(nil)
roomsManager.EXPECT().DeleteRoom(gomock.Any(), secondRoom).Return(serviceerrors.NewErrGameRoomStatusWaitingTimeout("some error"))
operationManager.EXPECT().AppendOperationEventToExecutionHistory(gomock.Any(), op, gomock.Any())
Expand All @@ -278,7 +242,7 @@ func TestExecutor_Execute(t *testing.T) {
})

t.Run("should succeed - there are ids and amount => return without error", func(t *testing.T) {
executor, roomsStorage, roomsManager, _ := testSetup(t)
executor, _, roomsManager, _ := testSetup(t)

firstRoomID := "first-room-id"
secondRoomID := "second-room-id"
Expand All @@ -292,16 +256,6 @@ func TestExecutor_Execute(t *testing.T) {
}
op := &operation.Operation{ID: "random-uuid", SchedulerName: schedulerName}

room := &game_room.GameRoom{
ID: firstRoomID,
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
}
secondRoom := &game_room.GameRoom{
ID: secondRoomID,
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
}
thirdRoom := &game_room.GameRoom{
ID: thirdRoomID,
SchedulerID: schedulerName,
Expand All @@ -312,8 +266,6 @@ func TestExecutor_Execute(t *testing.T) {
SchedulerID: schedulerName,
Status: game_room.GameStatusReady,
}
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, firstRoomID).Return(room, nil)
roomsStorage.EXPECT().GetRoom(gomock.Any(), schedulerName, secondRoomID).Return(secondRoom, nil)
roomsManager.EXPECT().DeleteRoom(gomock.Any(), gomock.Any()).Return(nil).Times(2)

availableRooms := []*game_room.GameRoom{thirdRoom, fourthRoom}
Expand Down

0 comments on commit 2136d07

Please sign in to comment.