优化结构

This commit is contained in:
Yvan
2026-08-28 09:19:54 +08:00
parent 03a4131f6e
commit 279692375b
57 changed files with 778 additions and 799 deletions
@@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"io"
"kra/internal/biz/system"
"strings"
"testing"
"time"
@@ -117,3 +118,38 @@ func TestAdvanceDeletePrefixCursor(t *testing.T) {
t.Fatalf("advance cursor = %q, %v", next, err)
}
}
func TestDeletePrefixViaListDeletesAllPages(t *testing.T) {
pages := map[string][]*system.StoredFile{
"": {{Path: "uploads/a"}, {Path: "uploads/b"}},
"next": {{Path: "uploads/c"}},
}
removed := []string{}
if err := deletePrefixViaList(context.Background(), "uploads", func(_ context.Context, prefix, cursor string, limit int) ([]*system.StoredFile, string, bool, error) {
if prefix != "uploads/" || limit != 1000 {
t.Fatalf("list arguments = %q, %q, %d", prefix, cursor, limit)
}
items := pages[cursor]
if cursor == "" {
return items, "next", true, nil
}
return items, "", false, nil
}, func(_ context.Context, path string) error {
removed = append(removed, path)
return nil
}); err != nil {
t.Fatal(err)
}
if len(removed) != 3 || removed[2] != "uploads/c" {
t.Fatalf("removed paths = %#v", removed)
}
}
func TestDeletePrefixViaListRejectsStalledCursor(t *testing.T) {
err := deletePrefixViaList(context.Background(), "uploads", func(_ context.Context, _, _ string, _ int) ([]*system.StoredFile, string, bool, error) {
return nil, "", true, nil
}, func(context.Context, string) error { return nil })
if err == nil || !strings.Contains(err.Error(), "no progress") {
t.Fatalf("stalled pagination error = %v", err)
}
}