-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6643c6a
commit be4588c
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,55 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
"github.com/bytedance/mockey" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/west2-online/fzuhelper-server/cmd/classroom/dal/cache" | ||
"github.com/west2-online/fzuhelper-server/kitex_gen/classroom" | ||
"testing" | ||
) | ||
|
||
func TestGetEmptyRoom_RoomInfoNotExist(t *testing.T) { | ||
classroomService := NewClassroomService(context.Background()) | ||
|
||
// 模拟请求参数 | ||
req := &classroom.EmptyRoomRequest{ | ||
Date: "2024-10-01", | ||
Campus: "旗山校区", | ||
StartTime: "1", | ||
EndTime: "1", | ||
} | ||
|
||
// Mock cache.IsExistRoomInfo 返回 false | ||
mockey.Mock(cache.IsExistRoomInfo).Return(false).Build() | ||
|
||
result, err := classroomService.GetEmptyRoom(req) | ||
|
||
// 断言返回结果 | ||
assert.Nil(t, result) | ||
assert.EqualError(t, err, "service.GetEmptyRoom: room info not exist") | ||
} | ||
|
||
func TestGetEmptyRoom_RoomInfoExist(t *testing.T) { | ||
classroomService := NewClassroomService(context.Background()) | ||
|
||
req := &classroom.EmptyRoomRequest{ | ||
Date: "2024-10-01", | ||
Campus: "旗山校区", | ||
StartTime: "1", | ||
EndTime: "1", | ||
} | ||
|
||
// Mock cache.IsExistRoomInfo 返回 true | ||
mockey.Mock(cache.IsExistRoomInfo).Return(true).Build() | ||
|
||
expectedRooms := []string{"旗山东1"} | ||
mockey.Mock(cache.GetEmptyRoomCache).Return(expectedRooms, nil).Build() | ||
|
||
// 调用 GetEmptyRoom 方法 | ||
result, err := classroomService.GetEmptyRoom(req) | ||
|
||
// 断言返回结果 | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedRooms, result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters