feat: complete API-driven projects with infrastructure and business acceptance

This commit is contained in:
2026-09-23 17:33:50 +08:00
parent 04a1f7999d
commit 2c74dc0859
137 changed files with 11926 additions and 105 deletions

View File

@@ -9,11 +9,13 @@ import (
"io"
"strings"
"testing"
"time"
)
func Run(t *testing.T, store storage.Store) {
t.Helper()
ctx := context.Background()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
key := "contract/文件 +%.txt"
defer store.Delete(ctx, key)
if _, err := store.Get(ctx, key); !errors.Is(err, storage.ErrNotFound) {
@@ -37,13 +39,19 @@ func Run(t *testing.T, store storage.Store) {
if _, err := store.Put(ctx, "tooBig", strings.NewReader(strings.Repeat("a", 65)), 65, "text/plain"); !errors.Is(err, storage.ErrTooLarge) {
t.Fatal(err)
}
for _, size := range []int64{0, 2, 4} {
if _, err := store.Put(ctx, "sizeMismatch", strings.NewReader("abc"), size, "text/plain"); err == nil {
t.Fatalf("declared size %d accepted for 3 bytes", size)
}
}
defer store.Delete(context.Background(), "sizeMismatch")
for _, key := range []string{"../bad", "a/../b", "/absolute", "a//b", "a\\b"} {
if _, err := store.Put(ctx, key, strings.NewReader("a"), 1, "text/plain"); err == nil {
t.Fatal(key)
}
}
canceled, cancel := context.WithCancel(ctx)
cancel()
canceled, cancelRequest := context.WithCancel(ctx)
cancelRequest()
if _, err := store.Get(canceled, key); !errors.Is(err, context.Canceled) {
t.Fatal(err)
}