Files
backend/internal/service/helpers_test.go
lafay 7d1c78f965
Some checks failed
Build / build (push) Successful in 7m52s
Build / build-docker (push) Has been cancelled
refactor: 移除全局单例、修复分层违规、统一错误与响应
2026-06-15 16:40:36 +08:00

32 lines
785 B
Go

package service
import (
"testing"
)
// TestNormalizePagination_Basic 覆盖 NormalizePagination 的边界分支
func TestNormalizePagination_Basic(t *testing.T) {
tests := []struct {
name string
page int
size int
wantPage int
wantPageSize int
}{
{"page 小于 1", 0, 10, 1, 10},
{"pageSize 小于 1", 1, 0, 1, 20},
{"pageSize 大于 100", 2, 200, 2, 100},
{"正常范围", 3, 30, 3, 30},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotPage, gotSize := NormalizePagination(tt.page, tt.size)
if gotPage != tt.wantPage || gotSize != tt.wantPageSize {
t.Fatalf("NormalizePagination(%d,%d) = (%d,%d), want (%d,%d)",
tt.page, tt.size, gotPage, gotSize, tt.wantPage, tt.wantPageSize)
}
})
}
}