Files
tenant-registry/internal/storage/storage_test.go
T
sharangandClaude Opus 5.5 b424e001dc
ci / shared (push) Successful in 13s
ci / test (push) Successful in 23m21s
ci / image (push) Successful in 35s
fix(storage): bound the upload part size so uploads don't OOM the registry (#44)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-09-28 09:21:07 +00:00

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")
}
}