新增通道服务相关测试用例
This commit is contained in:
@@ -2,30 +2,14 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"platform/pkg/rds"
|
||||
"platform/pkg/testutil"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/alicebob/miniredis/v2"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// 设置测试的 Redis 环境
|
||||
func setupRedisTest(t *testing.T) *miniredis.Miniredis {
|
||||
mr, err := miniredis.Run()
|
||||
if err != nil {
|
||||
t.Fatalf("设置 miniredis 失败: %v", err)
|
||||
}
|
||||
|
||||
// 替换 redis 客户端为测试客户端
|
||||
rds.Client = redis.NewClient(&redis.Options{
|
||||
Addr: mr.Addr(),
|
||||
})
|
||||
|
||||
return mr
|
||||
}
|
||||
|
||||
func Test_verifierService_SendSms(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
@@ -82,7 +66,7 @@ func Test_verifierService_SendSms(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// 设置 Redis 测试环境
|
||||
mr := setupRedisTest(t)
|
||||
mr := testutil.SetupRedisTest(t)
|
||||
defer mr.Close()
|
||||
|
||||
// 执行测试前的设置
|
||||
@@ -216,7 +200,7 @@ func Test_verifierService_VerifySms(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// 设置 Redis 测试环境
|
||||
mr := setupRedisTest(t)
|
||||
mr := testutil.SetupRedisTest(t)
|
||||
defer mr.Close()
|
||||
|
||||
// 执行测试前的设置
|
||||
|
||||
Reference in New Issue
Block a user