返回 DeepSeek-Reasonix
batch_limits_test.go
根目录 / internal / attachment / batch_limits_test.go
1 package attachment
2
3 import "testing"
4
5 func TestAdmissionCountAndByteBoundaries(t *testing.T) {
6 svc := testService(t)
7 image := opaquePNG(t, 1, 1)
8 sources := make([]Source, 21)
9 for i := range sources {
10 sources[i] = Source{Bytes: image}
11 }
12 if got, err := svc.PrepareBatch(t.Context(), sources[:20]); err != nil || len(got.Items) != 20 {
13 t.Fatalf("20 images: count=%d err=%v", len(got.Items), err)
14 }
15 if _, err := svc.PrepareBatch(t.Context(), sources); !Is(err, CodeTooMany) {
16 t.Fatalf("21 images: %v", err)
17 }
18 // Valid PNGs may contain trailing data. Share one immutable source buffer
19 // to exercise the real 200 MiB boundary without decoding giant rasters.
20 raw := make([]byte, MaxSourceBytes+1)
21 copy(raw, image)
22 if _, err := svc.PrepareBatch(t.Context(), []Source{{Bytes: raw[:MaxSourceBytes]}}); err != nil {
23 t.Fatalf("64 MiB: %v", err)
24 }
25 if _, err := svc.PrepareBatch(t.Context(), []Source{{Bytes: raw}}); !Is(err, CodeSize) {
26 t.Fatalf("64 MiB + 1: %v", err)
27 }
28 batch := []Source{{Bytes: raw[:50<<20]}, {Bytes: raw[:50<<20]}, {Bytes: raw[:50<<20]}, {Bytes: raw[:50<<20]}}
29 if _, err := svc.PrepareBatch(t.Context(), batch); err != nil {
30 t.Fatalf("200 MiB: %v", err)
31 }
32 batch[3].Bytes = raw[:(50<<20)+1]
33 if _, err := svc.PrepareBatch(t.Context(), batch); !Is(err, CodeBatchSize) {
34 t.Fatalf("200 MiB + 1: %v", err)
35 }
36 }
37
37 lines GO