Files
tenant-registry/internal/storage/storage_test.go
T
sharangandClaude Opus 5.5 8d3cda4bb0
ci / shared (push) Successful in 12s
ci / test (push) Successful in 23m15s
ci / image (push) Successful in 31s
feat(documents): tenant documents with staff upload and signed downloads (#34)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-09-23 20:31:55 +00:00

58 lines
1.6 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")
}
}