update
This commit is contained in:
@ -46,7 +46,13 @@ func TestAdminMixedListFilterAndOrder(t *testing.T) {
|
||||
|
||||
repo := NewAdminRepository(db)
|
||||
|
||||
all, total, err := repo.ListMixed(t.Context(), "", "", 1, 100)
|
||||
// 页大小必须显著大于库中总行数:本测试连的是**活库**(与开发库同一套 configs),
|
||||
// 重爬会持续写入 pending 行,而排序是「pending 优先、其次 id 倒序」——种子里的走秀是
|
||||
// published,恒排在所有 pending 之后。曾用固定 100,重爬把 pending 写到 115 行后,
|
||||
// 种子就被挤出第一页,断言随数据量随机失败(与被测逻辑无关)。
|
||||
const pageSize = 100000
|
||||
|
||||
all, total, err := repo.ListMixed(t.Context(), "", "", 1, pageSize)
|
||||
if err != nil {
|
||||
t.Fatalf("ListMixed 全部失败: %v", err)
|
||||
}
|
||||
@ -67,7 +73,7 @@ func TestAdminMixedListFilterAndOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
// 待审核过滤:街拍(pending) 出现,走秀(published) 不出现。
|
||||
pending, _, err := repo.ListMixed(t.Context(), "pending", "", 1, 100)
|
||||
pending, _, err := repo.ListMixed(t.Context(), "pending", "", 1, pageSize)
|
||||
if err != nil {
|
||||
t.Fatalf("ListMixed pending 失败: %v", err)
|
||||
}
|
||||
@ -164,11 +170,28 @@ func TestAdminMixedKindFilter(t *testing.T) {
|
||||
t.Fatalf("kind=street 至少应含 1 条")
|
||||
}
|
||||
|
||||
all, _, err := repo.ListMixed(ctx, "", "", 1, 50)
|
||||
// 注意:必须比对**总数**而非本页行数——三种查询都按 size=50 截断,
|
||||
// 库里 runway 超过 50 条时 len(all) 恒为 50,拿页长相加会假失败(与数据量相关的脆弱断言)。
|
||||
all, allTotal, err := repo.ListMixed(ctx, "", "", 1, 50)
|
||||
if err != nil {
|
||||
t.Fatalf("kind='' 失败: %v", err)
|
||||
}
|
||||
if len(all) != len(runwayOnly)+len(streetOnly) {
|
||||
t.Fatalf("全部应等于两类型之和:all=%d runway=%d street=%d", len(all), len(runwayOnly), len(streetOnly))
|
||||
_, runwayTotal, err := repo.ListMixed(ctx, "", "runway", 1, 50)
|
||||
if err != nil {
|
||||
t.Fatalf("kind=runway 计数失败: %v", err)
|
||||
}
|
||||
_, streetTotal, err := repo.ListMixed(ctx, "", "street", 1, 50)
|
||||
if err != nil {
|
||||
t.Fatalf("kind=street 计数失败: %v", err)
|
||||
}
|
||||
if allTotal != runwayTotal+streetTotal {
|
||||
t.Fatalf("全部总数应等于两类型之和:all=%d runway=%d street=%d", allTotal, runwayTotal, streetTotal)
|
||||
}
|
||||
// 本页行数不得超过分页上限,且 kind='' 的第一页应同时反映两种类型的存在。
|
||||
if len(all) == 0 {
|
||||
t.Fatal("kind='' 至少应含 1 条")
|
||||
}
|
||||
if len(all) > 50 {
|
||||
t.Fatalf("本页行数不应超过 size=50,实际 %d", len(all))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user