新增通道服务相关测试用例
This commit is contained in:
@@ -3,36 +3,12 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"platform/pkg/rds"
|
||||
"platform/pkg/testutil"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/alicebob/miniredis/v2"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// 设置 Redis 模拟服务器
|
||||
func setupTestRedis(t *testing.T) *miniredis.Miniredis {
|
||||
mr, err := miniredis.Run()
|
||||
if err != nil {
|
||||
t.Fatalf("无法启动 miniredis: %v", err)
|
||||
}
|
||||
|
||||
// 替换 Redis 客户端为测试客户端
|
||||
origClient := rds.Client
|
||||
rds.Client = redis.NewClient(&redis.Options{
|
||||
Addr: mr.Addr(),
|
||||
})
|
||||
|
||||
t.Cleanup(func() {
|
||||
mr.Close()
|
||||
rds.Client = origClient
|
||||
})
|
||||
|
||||
return mr
|
||||
}
|
||||
|
||||
// 创建测试用的认证上下文
|
||||
func createTestAuthContext() AuthContext {
|
||||
return AuthContext{
|
||||
@@ -52,7 +28,7 @@ func createTestAuthContext() AuthContext {
|
||||
}
|
||||
|
||||
func Test_sessionService_Create(t *testing.T) {
|
||||
mr := setupTestRedis(t)
|
||||
mr := testutil.SetupRedisTest(t)
|
||||
ctx := context.Background()
|
||||
auth := createTestAuthContext()
|
||||
|
||||
@@ -162,7 +138,7 @@ func Test_sessionService_Create(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_sessionService_Find(t *testing.T) {
|
||||
_ = setupTestRedis(t)
|
||||
testutil.SetupRedisTest(t)
|
||||
ctx := context.Background()
|
||||
auth := createTestAuthContext()
|
||||
s := &sessionService{}
|
||||
@@ -221,7 +197,7 @@ func Test_sessionService_Find(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_sessionService_Refresh(t *testing.T) {
|
||||
mr := setupTestRedis(t)
|
||||
mr := testutil.SetupRedisTest(t)
|
||||
ctx := context.Background()
|
||||
auth := createTestAuthContext()
|
||||
s := &sessionService{}
|
||||
@@ -314,7 +290,7 @@ func Test_sessionService_Refresh(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_sessionService_Remove(t *testing.T) {
|
||||
mr := setupTestRedis(t)
|
||||
mr := testutil.SetupRedisTest(t)
|
||||
ctx := context.Background()
|
||||
auth := createTestAuthContext()
|
||||
s := &sessionService{}
|
||||
|
||||
Reference in New Issue
Block a user