Files
user-system/internal/repository/integration_redis_suite.go
long-agent 582ad7a069 test: add comprehensive test coverage and improve code quality
- Add new test files for auth, service, and handler modules
- Improve test organization and coverage
- Refactor code for better maintainability
- Add captcha, settings, stats, and theme handler tests
- Add auth module tests (CAS, OAuth, password, SSO, state)
- Add service layer tests for auth, export, permissions, roles
- All Go tests pass (exit code 0)
- All frontend tests pass (325 tests in 59 files)
2026-04-17 20:43:50 +08:00

61 lines
1.2 KiB
Go

//go:build integration
package repository
import (
"context"
"time"
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/suite"
)
// IntegrationRedisSuite Redis 集成测试基础套件
// 所有 Redis 集成测试应嵌入此套件
type IntegrationRedisSuite struct {
suite.Suite
rdb *redis.Client
ctx context.Context
host string
port string
}
// SetupSuite 连接 Redis
func (s *IntegrationRedisSuite) SetupSuite() {
s.ctx = context.Background()
s.host = "localhost"
s.port = "6379"
s.rdb = redis.NewClient(&redis.Options{
Addr: s.host + ":" + s.port,
DialTimeout: 5 * time.Second,
ReadTimeout: 3 * time.Second,
WriteTimeout: 3 * time.Second,
PoolSize: 10,
})
}
// SetupTest 每个测试前清空数据库
func (s *IntegrationRedisSuite) SetupTest() {
if s.rdb == nil {
s.T().Skip("Redis not available, skipping integration test")
}
s.rdb.FlushDB(s.ctx)
}
// TearDownSuite 关闭连接
func (s *IntegrationRedisSuite) TearDownSuite() {
if s.rdb != nil {
s.rdb.Close()
}
}
// Redis 返回的辅助方法
func (s *IntegrationRedisSuite) Redis() *redis.Client {
return s.rdb
}
func (s *IntegrationRedisSuite) Context() context.Context {
return s.ctx
}