Uploads are streamed to S3 with an unknown size. minio-go then sizes one part for the largest possible object (528 MiB) and allocates it up front, which killed the registry at its 384 MiB limit on every upload (staging, S3 test of the acceptance run). A fixed 16 MiB part caps the buffer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestContentDisposition(t *testing.T) {
|
|
got := ContentDisposition(`Prüfbericht "Q3".pdf`)
|
|
want := `attachment; filename="Pr_fbericht _Q3_.pdf"; filename*=UTF-8''Pr%C3%BCfbericht%20%22Q3%22.pdf`
|
|
if got != want {
|
|
t.Fatalf("got %s\nwant %s", got, want)
|
|
}
|
|
}
|
|
|
|
func TestConfigured(t *testing.T) {
|
|
if (Config{}).Configured() {
|
|
t.Fatal("empty config is configured")
|
|
}
|
|
if !(Config{Endpoint: "https://x", Bucket: "b", AccessKey: "a", SecretKey: "s"}).Configured() {
|
|
t.Fatal("full config not configured")
|
|
}
|
|
}
|
|
|
|
func TestNewS3_rejectsBadEndpoint(t *testing.T) {
|
|
if _, err := NewS3(context.Background(), Config{Endpoint: "::nope", Bucket: "b", AccessKey: "a", SecretKey: "s"}); err == nil {
|
|
t.Fatal("bad endpoint accepted")
|
|
}
|
|
}
|
|
|
|
func TestMemory(t *testing.T) {
|
|
ctx := context.Background()
|
|
m := NewMemory()
|
|
if err := m.Put(ctx, "k", strings.NewReader("hello"), -1, "text/plain"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(m.Objects["k"]) != "hello" || m.Types["k"] != "text/plain" {
|
|
t.Fatalf("stored %q %q", m.Objects["k"], m.Types["k"])
|
|
}
|
|
u, err := m.PresignGet(ctx, "k", "a b.pdf", time.Minute)
|
|
if err != nil || !strings.Contains(u, "filename=a+b.pdf") {
|
|
t.Fatalf("presign %q %v", u, err)
|
|
}
|
|
if _, err := m.PresignGet(ctx, "missing", "x", time.Minute); err == nil {
|
|
t.Fatal("presign of a missing object")
|
|
}
|
|
if err := m.Delete(ctx, "k"); err != nil || len(m.Objects) != 0 {
|
|
t.Fatalf("delete %v", err)
|
|
}
|
|
m.FailPut = errors.New("boom")
|
|
if err := m.Put(ctx, "k", strings.NewReader("x"), 1, ""); err == nil {
|
|
t.Fatal("FailPut ignored")
|
|
}
|
|
}
|
|
|
|
// A streamed upload (size -1) must not make minio-go allocate a part sized
|
|
// for a 5 TiB object.
|
|
func TestPutOptions_boundPartSize(t *testing.T) {
|
|
o := putOptions("application/pdf")
|
|
if o.ContentType != "application/pdf" {
|
|
t.Fatalf("content type = %q", o.ContentType)
|
|
}
|
|
if o.PartSize != 16<<20 {
|
|
t.Fatalf("part size = %d, want 16 MiB", o.PartSize)
|
|
}
|
|
if o.ConcurrentStreamParts {
|
|
t.Fatal("concurrent stream parts would buffer several parts at once")
|
|
}
|
|
}
|