Changes: - Add FALSE_COMPLETION_PREVENTION.md documenting false completion patterns - Add integrity check script (scripts/check-integrity.sh) for automated verification - Fix swagger annotation gaps in 3 handlers (+10 annotations): - password_reset_handler.go: +4 annotations - totp_handler.go: +4 annotations - log_handler.go: +2 annotations - Define IntegrationRedisSuite type for Redis integration tests - Update QUALITY_STANDARD.md with swagger completeness and response format requirements - Update PROJECT_EXPERIENCE_SUMMARY.md with new learnings on false completion Integrity check now validates: - Swagger annotation completeness per handler - Response format uniformity (with OAuth whitelist) - Test infrastructure type definitions - Repository test coverage
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
//go:build integration
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"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
|
|
}
|