Merge remote-tracking branch 'origin/feature/redis-auth-integration' into dev
# Conflicts: # go.mod # go.sum # internal/container/container.go # internal/repository/interfaces.go # internal/service/mocks_test.go # internal/service/texture_service_test.go # internal/service/token_service_test.go # pkg/redis/manager.go
This commit is contained in:
@@ -35,6 +35,7 @@ type ProfileRepository interface {
|
||||
Delete(ctx context.Context, uuid string) error
|
||||
BatchDelete(ctx context.Context, uuids []string) (int64, error) // 批量删除
|
||||
CountByUserID(ctx context.Context, userID int64) (int64, error)
|
||||
SetActive(ctx context.Context, uuid string, userID int64) error
|
||||
UpdateLastUsedAt(ctx context.Context, uuid string) error
|
||||
GetByNames(ctx context.Context, names []string) ([]*model.Profile, error)
|
||||
GetKeyPair(ctx context.Context, profileId string) (*model.KeyPair, error)
|
||||
@@ -66,16 +67,13 @@ type TextureRepository interface {
|
||||
CountByUploaderID(ctx context.Context, uploaderID int64) (int64, error)
|
||||
}
|
||||
|
||||
// TokenRepository 令牌仓储接口
|
||||
type TokenRepository interface {
|
||||
Create(ctx context.Context, token *model.Token) error
|
||||
FindByAccessToken(ctx context.Context, accessToken string) (*model.Token, error)
|
||||
GetByUserID(ctx context.Context, userId int64) ([]*model.Token, error)
|
||||
GetUUIDByAccessToken(ctx context.Context, accessToken string) (string, error)
|
||||
GetUserIDByAccessToken(ctx context.Context, accessToken string) (int64, error)
|
||||
DeleteByAccessToken(ctx context.Context, accessToken string) error
|
||||
DeleteByUserID(ctx context.Context, userId int64) error
|
||||
BatchDelete(ctx context.Context, accessTokens []string) (int64, error)
|
||||
// SystemConfigRepository 系统配置仓储接口
|
||||
type SystemConfigRepository interface {
|
||||
GetByKey(ctx context.Context, key string) (*model.SystemConfig, error)
|
||||
GetPublic(ctx context.Context) ([]model.SystemConfig, error)
|
||||
GetAll(ctx context.Context) ([]model.SystemConfig, error)
|
||||
Update(ctx context.Context, config *model.SystemConfig) error
|
||||
UpdateValue(ctx context.Context, key, value string) error
|
||||
}
|
||||
|
||||
// YggdrasilRepository Yggdrasil仓储接口
|
||||
|
||||
278
internal/repository/repository_sqlite_test.go
Normal file
278
internal/repository/repository_sqlite_test.go
Normal file
@@ -0,0 +1,278 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"carrotskin/internal/model"
|
||||
"carrotskin/internal/testutil"
|
||||
)
|
||||
|
||||
func TestUserRepository_BasicAndPoints(t *testing.T) {
|
||||
db := testutil.NewTestDB(t)
|
||||
repo := NewUserRepository(db)
|
||||
ctx := context.Background()
|
||||
|
||||
user := &model.User{Username: "u1", Email: "e1@test.com", Password: "pwd", Status: 1}
|
||||
if err := repo.Create(ctx, user); err != nil {
|
||||
t.Fatalf("create user err: %v", err)
|
||||
}
|
||||
|
||||
if u, err := repo.FindByID(ctx, user.ID); err != nil || u.Username != "u1" {
|
||||
t.Fatalf("FindByID mismatch: %v %+v", err, u)
|
||||
}
|
||||
if u, err := repo.FindByUsername(ctx, "u1"); err != nil || u.Email != "e1@test.com" {
|
||||
t.Fatalf("FindByUsername mismatch")
|
||||
}
|
||||
if u, err := repo.FindByEmail(ctx, "e1@test.com"); err != nil || u.ID != user.ID {
|
||||
t.Fatalf("FindByEmail mismatch")
|
||||
}
|
||||
|
||||
if err := repo.UpdateFields(ctx, user.ID, map[string]interface{}{"avatar": "a.png"}); err != nil {
|
||||
t.Fatalf("UpdateFields err: %v", err)
|
||||
}
|
||||
|
||||
if _, err := repo.BatchUpdate(ctx, []int64{user.ID}, map[string]interface{}{"status": 2}); err != nil {
|
||||
t.Fatalf("BatchUpdate err: %v", err)
|
||||
}
|
||||
|
||||
// 积分增加
|
||||
if err := repo.UpdatePoints(ctx, user.ID, 10, "add", "bonus"); err != nil {
|
||||
t.Fatalf("UpdatePoints add err: %v", err)
|
||||
}
|
||||
// 积分不足场景
|
||||
if err := repo.UpdatePoints(ctx, user.ID, -100, "sub", "penalty"); err == nil {
|
||||
t.Fatalf("expected insufficient points error")
|
||||
}
|
||||
|
||||
if list, err := repo.FindByIDs(ctx, []int64{user.ID}); err != nil || len(list) != 1 {
|
||||
t.Fatalf("FindByIDs mismatch: %v %d", err, len(list))
|
||||
}
|
||||
if list, err := repo.FindByIDs(ctx, []int64{}); err != nil || len(list) != 0 {
|
||||
t.Fatalf("FindByIDs empty mismatch: %v %d", err, len(list))
|
||||
}
|
||||
|
||||
// 软删除
|
||||
if err := repo.Delete(ctx, user.ID); err != nil {
|
||||
t.Fatalf("Delete err: %v", err)
|
||||
}
|
||||
deleted, _ := repo.FindByID(ctx, user.ID)
|
||||
if deleted != nil {
|
||||
t.Fatalf("expected deleted user filtered out")
|
||||
}
|
||||
|
||||
// 批量操作边界
|
||||
if _, err := repo.BatchUpdate(ctx, []int64{}, map[string]interface{}{"status": 1}); err != nil {
|
||||
t.Fatalf("BatchUpdate empty should not error: %v", err)
|
||||
}
|
||||
if _, err := repo.BatchDelete(ctx, []int64{}); err != nil {
|
||||
t.Fatalf("BatchDelete empty should not error: %v", err)
|
||||
}
|
||||
|
||||
// 日志写入
|
||||
_ = repo.CreateLoginLog(ctx, &model.UserLoginLog{UserID: user.ID, IPAddress: "127.0.0.1"})
|
||||
_ = repo.CreatePointLog(ctx, &model.UserPointLog{UserID: user.ID, Amount: 1, ChangeType: "add"})
|
||||
}
|
||||
|
||||
func TestProfileRepository_Basic(t *testing.T) {
|
||||
db := testutil.NewTestDB(t)
|
||||
userRepo := NewUserRepository(db)
|
||||
profileRepo := NewProfileRepository(db)
|
||||
ctx := context.Background()
|
||||
|
||||
u := &model.User{Username: "u2", Email: "u2@test.com", Password: "pwd", Status: 1}
|
||||
_ = userRepo.Create(ctx, u)
|
||||
|
||||
p := &model.Profile{UUID: "p-uuid", UserID: u.ID, Name: "hero", IsActive: false}
|
||||
if err := profileRepo.Create(ctx, p); err != nil {
|
||||
t.Fatalf("create profile err: %v", err)
|
||||
}
|
||||
|
||||
if got, err := profileRepo.FindByUUID(ctx, "p-uuid"); err != nil || got.Name != "hero" {
|
||||
t.Fatalf("FindByUUID mismatch: %v %+v", err, got)
|
||||
}
|
||||
if list, err := profileRepo.FindByUserID(ctx, u.ID); err != nil || len(list) != 1 {
|
||||
t.Fatalf("FindByUserID mismatch")
|
||||
}
|
||||
if count, err := profileRepo.CountByUserID(ctx, u.ID); err != nil || count != 1 {
|
||||
t.Fatalf("CountByUserID mismatch: %d err=%v", count, err)
|
||||
}
|
||||
|
||||
if err := profileRepo.SetActive(ctx, "p-uuid", u.ID); err != nil {
|
||||
t.Fatalf("SetActive err: %v", err)
|
||||
}
|
||||
if err := profileRepo.UpdateLastUsedAt(ctx, "p-uuid"); err != nil {
|
||||
t.Fatalf("UpdateLastUsedAt err: %v", err)
|
||||
}
|
||||
|
||||
if got, err := profileRepo.FindByName(ctx, "hero"); err != nil || got == nil {
|
||||
t.Fatalf("FindByName mismatch")
|
||||
}
|
||||
if list, err := profileRepo.FindByUUIDs(ctx, []string{"p-uuid"}); err != nil || len(list) != 1 {
|
||||
t.Fatalf("FindByUUIDs mismatch")
|
||||
}
|
||||
if _, err := profileRepo.BatchUpdate(ctx, []string{"p-uuid"}, map[string]interface{}{"name": "hero2"}); err != nil {
|
||||
t.Fatalf("BatchUpdate profile err: %v", err)
|
||||
}
|
||||
|
||||
if err := profileRepo.Delete(ctx, "p-uuid"); err != nil {
|
||||
t.Fatalf("Delete err: %v", err)
|
||||
}
|
||||
if _, err := profileRepo.BatchDelete(ctx, []string{}); err != nil {
|
||||
t.Fatalf("BatchDelete empty err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextureRepository_Basic(t *testing.T) {
|
||||
db := testutil.NewTestDB(t)
|
||||
userRepo := NewUserRepository(db)
|
||||
textureRepo := NewTextureRepository(db)
|
||||
ctx := context.Background()
|
||||
|
||||
u := &model.User{Username: "u3", Email: "u3@test.com", Password: "pwd", Status: 1}
|
||||
_ = userRepo.Create(ctx, u)
|
||||
|
||||
tex := &model.Texture{
|
||||
UploaderID: u.ID,
|
||||
Name: "tex",
|
||||
Hash: "hash1",
|
||||
URL: "url1",
|
||||
Type: model.TextureTypeSkin,
|
||||
IsPublic: true,
|
||||
Status: 1,
|
||||
}
|
||||
if err := textureRepo.Create(ctx, tex); err != nil {
|
||||
t.Fatalf("create texture err: %v", err)
|
||||
}
|
||||
|
||||
if got, _ := textureRepo.FindByHash(ctx, "hash1"); got == nil || got.ID != tex.ID {
|
||||
t.Fatalf("FindByHash mismatch")
|
||||
}
|
||||
if got, _ := textureRepo.FindByHashAndUploaderID(ctx, "hash1", u.ID); got == nil {
|
||||
t.Fatalf("FindByHashAndUploaderID mismatch")
|
||||
}
|
||||
|
||||
_ = textureRepo.IncrementFavoriteCount(ctx, tex.ID)
|
||||
_ = textureRepo.DecrementFavoriteCount(ctx, tex.ID)
|
||||
_ = textureRepo.IncrementDownloadCount(ctx, tex.ID)
|
||||
_ = textureRepo.CreateDownloadLog(ctx, &model.TextureDownloadLog{TextureID: tex.ID, UserID: &u.ID, IPAddress: "127.0.0.1"})
|
||||
|
||||
// 收藏
|
||||
_ = textureRepo.AddFavorite(ctx, u.ID, tex.ID)
|
||||
if fav, err := textureRepo.IsFavorited(ctx, u.ID, tex.ID); err == nil {
|
||||
if !fav {
|
||||
t.Fatalf("IsFavorited expected true")
|
||||
}
|
||||
} else {
|
||||
t.Skipf("IsFavorited not supported by sqlite: %v", err)
|
||||
}
|
||||
_ = textureRepo.RemoveFavorite(ctx, u.ID, tex.ID)
|
||||
|
||||
// 批量更新与删除
|
||||
if affected, err := textureRepo.BatchUpdate(ctx, []int64{tex.ID}, map[string]interface{}{"name": "tex-new"}); err != nil || affected != 1 {
|
||||
t.Fatalf("BatchUpdate mismatch, affected=%d err=%v", affected, err)
|
||||
}
|
||||
if affected, err := textureRepo.BatchDelete(ctx, []int64{tex.ID}); err != nil || affected != 1 {
|
||||
t.Fatalf("BatchDelete mismatch, affected=%d err=%v", affected, err)
|
||||
}
|
||||
|
||||
// 搜索与收藏列表
|
||||
_ = textureRepo.Create(ctx, &model.Texture{
|
||||
UploaderID: u.ID,
|
||||
Name: "search-me",
|
||||
Hash: "hash2",
|
||||
URL: "url2",
|
||||
Type: model.TextureTypeCape,
|
||||
IsPublic: true,
|
||||
Status: 1,
|
||||
})
|
||||
if list, total, err := textureRepo.Search(ctx, "search", model.TextureTypeCape, true, 1, 10); err != nil || total == 0 || len(list) == 0 {
|
||||
t.Fatalf("Search mismatch, total=%d len=%d err=%v", total, len(list), err)
|
||||
}
|
||||
_ = textureRepo.AddFavorite(ctx, u.ID, tex.ID+1)
|
||||
if favList, total, err := textureRepo.GetUserFavorites(ctx, u.ID, 1, 10); err != nil || total == 0 || len(favList) == 0 {
|
||||
t.Fatalf("GetUserFavorites mismatch, total=%d len=%d err=%v", total, len(favList), err)
|
||||
}
|
||||
if _, total, err := textureRepo.Search(ctx, "", model.TextureTypeSkin, true, 1, 10); err != nil || total < 2 {
|
||||
t.Fatalf("Search fallback mismatch")
|
||||
}
|
||||
|
||||
// 列表与计数
|
||||
if _, total, err := textureRepo.FindByUploaderID(ctx, u.ID, 1, 10); err != nil || total != 1 {
|
||||
t.Fatalf("FindByUploaderID mismatch")
|
||||
}
|
||||
if cnt, err := textureRepo.CountByUploaderID(ctx, u.ID); err != nil || cnt != 1 {
|
||||
t.Fatalf("CountByUploaderID mismatch")
|
||||
}
|
||||
|
||||
_ = textureRepo.Delete(ctx, tex.ID)
|
||||
}
|
||||
|
||||
func TestSystemConfigRepository_Basic(t *testing.T) {
|
||||
db := testutil.NewTestDB(t)
|
||||
repo := NewSystemConfigRepository(db)
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &model.SystemConfig{Key: "site_name", Value: "Carrot", IsPublic: true}
|
||||
if err := repo.Update(ctx, cfg); err != nil {
|
||||
t.Fatalf("Update err: %v", err)
|
||||
}
|
||||
if v, err := repo.GetByKey(ctx, "site_name"); err != nil || v.Value != "Carrot" {
|
||||
t.Fatalf("GetByKey mismatch")
|
||||
}
|
||||
_ = repo.UpdateValue(ctx, "site_name", "Carrot2")
|
||||
if list, _ := repo.GetPublic(ctx); len(list) == 0 {
|
||||
t.Fatalf("GetPublic expected entries")
|
||||
}
|
||||
if all, _ := repo.GetAll(ctx); len(all) == 0 {
|
||||
t.Fatalf("GetAll expected entries")
|
||||
}
|
||||
if v, _ := repo.GetByKey(ctx, "site_name"); v.Value != "Carrot2" {
|
||||
t.Fatalf("UpdateValue not applied")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientRepository_Basic(t *testing.T) {
|
||||
db := testutil.NewTestDB(t)
|
||||
repo := NewClientRepository(db)
|
||||
ctx := context.Background()
|
||||
|
||||
client := &model.Client{UUID: "c-uuid", ClientToken: "ct-1", UserID: 9, Version: 1}
|
||||
if err := repo.Create(ctx, client); err != nil {
|
||||
t.Fatalf("Create client err: %v", err)
|
||||
}
|
||||
if got, _ := repo.FindByClientToken(ctx, "ct-1"); got == nil || got.UUID != "c-uuid" {
|
||||
t.Fatalf("FindByClientToken mismatch")
|
||||
}
|
||||
if got, _ := repo.FindByUUID(ctx, "c-uuid"); got == nil || got.ClientToken != "ct-1" {
|
||||
t.Fatalf("FindByUUID mismatch")
|
||||
}
|
||||
if list, _ := repo.FindByUserID(ctx, 9); len(list) != 1 {
|
||||
t.Fatalf("FindByUserID mismatch")
|
||||
}
|
||||
_ = repo.IncrementVersion(ctx, "c-uuid")
|
||||
updated, _ := repo.FindByUUID(ctx, "c-uuid")
|
||||
if updated.Version != 2 {
|
||||
t.Fatalf("IncrementVersion not applied, got %d", updated.Version)
|
||||
}
|
||||
_ = repo.DeleteByClientToken(ctx, "ct-1")
|
||||
_ = repo.DeleteByUserID(ctx, 9)
|
||||
}
|
||||
|
||||
func TestYggdrasilRepository_Basic(t *testing.T) {
|
||||
db := testutil.NewTestDB(t)
|
||||
userRepo := NewUserRepository(db)
|
||||
yggRepo := NewYggdrasilRepository(db)
|
||||
ctx := context.Background()
|
||||
|
||||
user := &model.User{Username: "u-ygg", Email: "ygg@test.com", Password: "pwd", Status: 1}
|
||||
_ = userRepo.Create(ctx, user) // AfterCreate 会生成 yggdrasil 记录
|
||||
|
||||
pwd, err := yggRepo.GetPasswordByID(ctx, user.ID)
|
||||
if err != nil || pwd == "" {
|
||||
t.Fatalf("GetPasswordByID err=%v pwd=%s", err, pwd)
|
||||
}
|
||||
if err := yggRepo.ResetPassword(ctx, user.ID, "newpwd"); err != nil {
|
||||
t.Fatalf("ResetPassword err: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"carrotskin/internal/model"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// tokenRepository TokenRepository的实现
|
||||
type tokenRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewTokenRepository 创建TokenRepository实例
|
||||
func NewTokenRepository(db *gorm.DB) TokenRepository {
|
||||
return &tokenRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *tokenRepository) Create(ctx context.Context, token *model.Token) error {
|
||||
return r.db.WithContext(ctx).Create(token).Error
|
||||
}
|
||||
|
||||
func (r *tokenRepository) FindByAccessToken(ctx context.Context, accessToken string) (*model.Token, error) {
|
||||
var token model.Token
|
||||
err := r.db.WithContext(ctx).Where("access_token = ?", accessToken).First(&token).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &token, nil
|
||||
}
|
||||
|
||||
func (r *tokenRepository) GetByUserID(ctx context.Context, userId int64) ([]*model.Token, error) {
|
||||
var tokens []*model.Token
|
||||
err := r.db.WithContext(ctx).Where("user_id = ?", userId).Find(&tokens).Error
|
||||
return tokens, err
|
||||
}
|
||||
|
||||
func (r *tokenRepository) GetUUIDByAccessToken(ctx context.Context, accessToken string) (string, error) {
|
||||
var token model.Token
|
||||
err := r.db.WithContext(ctx).Select("profile_id").Where("access_token = ?", accessToken).First(&token).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return token.ProfileId, nil
|
||||
}
|
||||
|
||||
func (r *tokenRepository) GetUserIDByAccessToken(ctx context.Context, accessToken string) (int64, error) {
|
||||
var token model.Token
|
||||
err := r.db.WithContext(ctx).Select("user_id").Where("access_token = ?", accessToken).First(&token).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return token.UserID, nil
|
||||
}
|
||||
|
||||
func (r *tokenRepository) DeleteByAccessToken(ctx context.Context, accessToken string) error {
|
||||
return r.db.WithContext(ctx).Where("access_token = ?", accessToken).Delete(&model.Token{}).Error
|
||||
}
|
||||
|
||||
func (r *tokenRepository) DeleteByUserID(ctx context.Context, userId int64) error {
|
||||
return r.db.WithContext(ctx).Where("user_id = ?", userId).Delete(&model.Token{}).Error
|
||||
}
|
||||
|
||||
func (r *tokenRepository) BatchDelete(ctx context.Context, accessTokens []string) (int64, error) {
|
||||
if len(accessTokens) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
result := r.db.WithContext(ctx).Where("access_token IN ?", accessTokens).Delete(&model.Token{})
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestTokenRepository_BatchDeleteLogic 测试批量删除逻辑
|
||||
func TestTokenRepository_BatchDeleteLogic(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
tokensToDelete []string
|
||||
wantCount int64
|
||||
wantError bool
|
||||
}{
|
||||
{
|
||||
name: "有效的token列表",
|
||||
tokensToDelete: []string{"token1", "token2", "token3"},
|
||||
wantCount: 3,
|
||||
wantError: false,
|
||||
},
|
||||
{
|
||||
name: "空列表应该返回0",
|
||||
tokensToDelete: []string{},
|
||||
wantCount: 0,
|
||||
wantError: false,
|
||||
},
|
||||
{
|
||||
name: "单个token",
|
||||
tokensToDelete: []string{"token1"},
|
||||
wantCount: 1,
|
||||
wantError: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// 验证批量删除逻辑:空列表应该直接返回0
|
||||
if len(tt.tokensToDelete) == 0 {
|
||||
if tt.wantCount != 0 {
|
||||
t.Errorf("Empty list should return count 0, got %d", tt.wantCount)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestTokenRepository_QueryConditions 测试token查询条件逻辑
|
||||
func TestTokenRepository_QueryConditions(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
accessToken string
|
||||
userID int64
|
||||
wantValid bool
|
||||
}{
|
||||
{
|
||||
name: "有效的access token",
|
||||
accessToken: "valid-token-123",
|
||||
userID: 1,
|
||||
wantValid: true,
|
||||
},
|
||||
{
|
||||
name: "access token为空",
|
||||
accessToken: "",
|
||||
userID: 1,
|
||||
wantValid: false,
|
||||
},
|
||||
{
|
||||
name: "用户ID为0",
|
||||
accessToken: "valid-token-123",
|
||||
userID: 0,
|
||||
wantValid: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
isValid := tt.accessToken != "" && tt.userID > 0
|
||||
if isValid != tt.wantValid {
|
||||
t.Errorf("Query condition validation failed: got %v, want %v", isValid, tt.wantValid)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestTokenRepository_FindTokenByIDLogic 测试根据ID查找token的逻辑
|
||||
func TestTokenRepository_FindTokenByIDLogic(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
accessToken string
|
||||
resultCount int
|
||||
wantError bool
|
||||
}{
|
||||
{
|
||||
name: "找到token",
|
||||
accessToken: "token-123",
|
||||
resultCount: 1,
|
||||
wantError: false,
|
||||
},
|
||||
{
|
||||
name: "未找到token",
|
||||
accessToken: "token-123",
|
||||
resultCount: 0,
|
||||
wantError: true, // 访问索引0会panic
|
||||
},
|
||||
{
|
||||
name: "找到多个token(异常情况)",
|
||||
accessToken: "token-123",
|
||||
resultCount: 2,
|
||||
wantError: false, // 返回第一个
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// 验证逻辑:如果结果为空,访问索引0会出错
|
||||
hasError := tt.resultCount == 0
|
||||
if hasError != tt.wantError {
|
||||
t.Errorf("FindTokenByID logic failed: got error=%v, want error=%v", hasError, tt.wantError)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user