mirror of
https://github.com/warmbly/warmbly.git
synced 2026-09-09 08:03:38 +00:00
One Store interface (Get/Put/Delete/Has/PresignedGetURL/Name) covers both the AWS S3 client (now exposes high-level methods alongside the legacy embedded *s3.Client) and a new FilesystemStore for self-hosters. FilesystemStore writes atomically via temp-file + rename, rejects '..' in keys before path normalization, returns ErrUnsupported from PresignedGetURL. The S3 impl works against AWS S3, MinIO, Cloudflare R2, Backblaze B2, and Hetzner Object Storage via standard AWS endpoint-URL config. Factory NewFromEnv selects via BLOB_PROVIDER (defaults to s3). 14 tests cover round-trip, ErrNotFound, atomic-write cleanup, traversal rejection, factory env-selection paths.
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
)
|
|
|
|
func TestNewFromEnv_UnknownProvider(t *testing.T) {
|
|
t.Setenv("BLOB_PROVIDER", "garage-but-not-really")
|
|
_, err := NewFromEnv(context.Background(), aws.Config{}, "")
|
|
if err == nil {
|
|
t.Fatal("expected error for unknown provider")
|
|
}
|
|
}
|
|
|
|
func TestNewFromEnv_FilesystemNeedsRoot(t *testing.T) {
|
|
t.Setenv("BLOB_PROVIDER", "filesystem")
|
|
t.Setenv("BLOB_FS_ROOT", "")
|
|
if _, err := NewFromEnv(context.Background(), aws.Config{}, ""); err == nil {
|
|
t.Fatal("filesystem provider should require BLOB_FS_ROOT")
|
|
}
|
|
}
|
|
|
|
func TestNewFromEnv_FilesystemHappy(t *testing.T) {
|
|
t.Setenv("BLOB_PROVIDER", "filesystem")
|
|
t.Setenv("BLOB_FS_ROOT", t.TempDir())
|
|
s, err := NewFromEnv(context.Background(), aws.Config{}, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s.Name() != "filesystem" {
|
|
t.Fatalf("expected filesystem, got %q", s.Name())
|
|
}
|
|
}
|
|
|
|
func TestNewFromEnv_S3NeedsBucket(t *testing.T) {
|
|
t.Setenv("BLOB_PROVIDER", "s3")
|
|
t.Setenv("BLOB_BUCKET", "")
|
|
if _, err := NewFromEnv(context.Background(), aws.Config{}, ""); err == nil {
|
|
t.Fatal("s3 provider should require BLOB_BUCKET or fallback bucket")
|
|
}
|
|
}
|
|
|
|
func TestNewFromEnv_S3WithFallbackBucket(t *testing.T) {
|
|
t.Setenv("BLOB_PROVIDER", "s3")
|
|
t.Setenv("BLOB_BUCKET", "")
|
|
s, err := NewFromEnv(context.Background(), aws.Config{}, "fallback-bucket")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s.Name() != "s3" {
|
|
t.Fatalf("expected s3, got %q", s.Name())
|
|
}
|
|
}
|
|
|
|
func TestNewFromEnv_FSAlias(t *testing.T) {
|
|
t.Setenv("BLOB_PROVIDER", "fs")
|
|
t.Setenv("BLOB_FS_ROOT", t.TempDir())
|
|
s, err := NewFromEnv(context.Background(), aws.Config{}, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s.Name() != "filesystem" {
|
|
t.Fatalf("expected filesystem, got %q", s.Name())
|
|
}
|
|
}
|