修改部分枚举字段的编号与注释确保 0 值的正确语义
This commit is contained in:
@@ -34,9 +34,8 @@ func Test_sessionService_Create(t *testing.T) {
|
||||
auth := createTestAuthContext()
|
||||
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
auth AuthContext
|
||||
config []SessionConfig
|
||||
ctx context.Context
|
||||
auth AuthContext
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -45,7 +44,7 @@ func Test_sessionService_Create(t *testing.T) {
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "使用默认配置创建会话",
|
||||
name: "创建会话",
|
||||
args: args{
|
||||
ctx: ctx,
|
||||
auth: auth,
|
||||
@@ -68,53 +67,13 @@ func Test_sessionService_Create(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "使用自定义配置创建会话",
|
||||
args: args{
|
||||
ctx: ctx,
|
||||
auth: auth,
|
||||
config: []SessionConfig{
|
||||
{
|
||||
AccessTokenDuration: 10 * time.Minute,
|
||||
RefreshTokenDuration: 24 * time.Hour,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: func(td *TokenDetails) bool {
|
||||
// 验证令牌存在且格式正确
|
||||
if td.AccessToken == "" || td.RefreshToken == "" {
|
||||
return false
|
||||
}
|
||||
// 验证到期时间在未来且接近预期时间
|
||||
now := time.Now()
|
||||
expectedAccessExpiry := now.Add(10 * time.Minute)
|
||||
expectedRefreshExpiry := now.Add(24 * time.Hour)
|
||||
|
||||
accessDiff := td.AccessTokenExpires.Sub(expectedAccessExpiry)
|
||||
refreshDiff := td.RefreshTokenExpires.Sub(expectedRefreshExpiry)
|
||||
|
||||
if accessDiff < -2*time.Second || accessDiff > 2*time.Second {
|
||||
return false
|
||||
}
|
||||
if refreshDiff < -2*time.Second || refreshDiff > 2*time.Second {
|
||||
return false
|
||||
}
|
||||
|
||||
// 验证认证信息正确
|
||||
if !reflect.DeepEqual(td.Auth, auth) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mr.FlushAll()
|
||||
s := &sessionService{}
|
||||
got, err := s.Create(tt.args.ctx, tt.args.auth, tt.args.config...)
|
||||
got, err := s.Create(tt.args.ctx, tt.args.auth, true)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Create() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
@@ -145,7 +104,7 @@ func Test_sessionService_Find(t *testing.T) {
|
||||
s := &sessionService{}
|
||||
|
||||
// 创建一个有效的会话
|
||||
td, err := s.Create(ctx, auth)
|
||||
td, err := s.Create(ctx, auth, true)
|
||||
if err != nil {
|
||||
t.Fatalf("无法创建测试会话: %v", err)
|
||||
}
|
||||
@@ -204,7 +163,7 @@ func Test_sessionService_Refresh(t *testing.T) {
|
||||
s := &sessionService{}
|
||||
|
||||
// 创建一个初始会话
|
||||
td, err := s.Create(ctx, auth)
|
||||
td, err := s.Create(ctx, auth, true)
|
||||
if err != nil {
|
||||
t.Fatalf("无法创建初始会话: %v", err)
|
||||
}
|
||||
@@ -216,7 +175,6 @@ func Test_sessionService_Refresh(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
refreshToken string
|
||||
config []SessionConfig
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -259,7 +217,7 @@ func Test_sessionService_Refresh(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := s.Refresh(tt.args.ctx, tt.args.refreshToken, tt.args.config...)
|
||||
got, err := s.Refresh(tt.args.ctx, tt.args.refreshToken)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Refresh() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
@@ -297,7 +255,7 @@ func Test_sessionService_Remove(t *testing.T) {
|
||||
s := &sessionService{}
|
||||
|
||||
// 创建一个会话
|
||||
td, err := s.Create(ctx, auth)
|
||||
td, err := s.Create(ctx, auth, true)
|
||||
if err != nil {
|
||||
t.Fatalf("无法创建测试会话: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user