Files
user-system/internal/domain/social_account.go
long-agent 8655b39b03 test: 完善方案一业务逻辑测试和方案二规模测试
方案一(业务逻辑正确性测试):
- 修复 SocialAccount.CreatedAt/UpdatedAt NULL 扫描问题(改为 *time.Time 指针)
- 修复 OPLOG_003~006 数据隔离(改用唯一前缀+Search方法隔离)
- 修复 DEV_008 设备列表测试(改用UserID过滤器隔离)
- 修复并发测试 cache=private → cache=shared(SQLite连接共享)
- 新增 testEnv 隔离架构(独立DB + 独立 httptest.Server)

方案二(真实数据规模测试):
- 新增 LatencyStats P99/P95 百分位统计采集器
- 全部 16 个测试迁移至 newIsolatedDB(独立内存DB,WAL模式)
- 关键查询添加 P99 多次采样统计(UL/LL/DV/DS/PR/AUTH/OPLOG)
- 新增 CONC_SCALE_001~003 并发压测(50-100 goroutine)
- 删除旧 setupScaleTestDB 死代码
- 双阈值体系:SQLite本地宽松阈值 vs PostgreSQL生产严格目标

共计 84 测试通过(68 业务逻辑 + 16 规模测试)
2026-04-07 07:23:29 +08:00

80 lines
2.3 KiB
Go

package domain
import (
"database/sql/driver"
"encoding/json"
"time"
)
// SocialAccount models a persisted OAuth binding.
type SocialAccount struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
UserID int64 `gorm:"index;not null" json:"user_id"`
Provider string `gorm:"type:varchar(50);not null" json:"provider"`
OpenID string `gorm:"type:varchar(100);not null" json:"open_id"`
UnionID string `gorm:"type:varchar(100)" json:"union_id,omitempty"`
Nickname string `gorm:"type:varchar(100)" json:"nickname"`
Avatar string `gorm:"type:varchar(500)" json:"avatar"`
Gender string `gorm:"type:varchar(10)" json:"gender,omitempty"`
Email string `gorm:"type:varchar(100)" json:"email,omitempty"`
Phone string `gorm:"type:varchar(20)" json:"phone,omitempty"`
Extra ExtraData `gorm:"type:text" json:"extra,omitempty"`
Status SocialAccountStatus `gorm:"default:1" json:"status"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
}
func (SocialAccount) TableName() string {
return "user_social_accounts"
}
type SocialAccountStatus int
const (
SocialAccountStatusActive SocialAccountStatus = 1
SocialAccountStatusInactive SocialAccountStatus = 0
SocialAccountStatusDisabled SocialAccountStatus = 2
)
type ExtraData map[string]interface{}
func (e ExtraData) Value() (driver.Value, error) {
if e == nil {
return nil, nil
}
return json.Marshal(e)
}
func (e *ExtraData) Scan(value interface{}) error {
if value == nil {
*e = nil
return nil
}
bytes, ok := value.([]byte)
if !ok {
return nil
}
return json.Unmarshal(bytes, e)
}
type SocialAccountInfo struct {
ID int64 `json:"id"`
Provider string `json:"provider"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Status SocialAccountStatus `json:"status"`
CreatedAt *time.Time `json:"created_at"`
}
func (s *SocialAccount) ToInfo() *SocialAccountInfo {
createdAt := s.CreatedAt
return &SocialAccountInfo{
ID: s.ID,
Provider: s.Provider,
Nickname: s.Nickname,
Avatar: s.Avatar,
Status: s.Status,
CreatedAt: createdAt,
}
}