优化结构
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user