Changeset 0.22.8 (#150)

This commit is contained in:
2026-03-04 16:06:12 +00:00
parent 389e47b0f9
commit 7e26a2a261
114 changed files with 3700 additions and 7572 deletions

View File

@@ -44,9 +44,9 @@ func TestS3_FullKey(t *testing.T) {
key string
want string
}{
{"", "attachments/ch/f.txt", "attachments/ch/f.txt"},
{"switchboard/", "attachments/ch/f.txt", "switchboard/attachments/ch/f.txt"},
{"prefix", "attachments/ch/f.txt", "prefix/attachments/ch/f.txt"}, // trailing slash added by NewS3
{"", "files/ch/f.txt", "files/ch/f.txt"},
{"switchboard/", "files/ch/f.txt", "switchboard/files/ch/f.txt"},
{"prefix", "files/ch/f.txt", "prefix/files/ch/f.txt"}, // trailing slash added by NewS3
}
for _, tt := range tests {
@@ -68,7 +68,7 @@ func TestS3_KeyValidation(t *testing.T) {
"",
"../etc/passwd",
"/absolute/path",
"attachments/../../etc/shadow",
"files/../../etc/shadow",
}
for _, key := range bad {
if err := validateKey(key); err == nil {
@@ -77,8 +77,8 @@ func TestS3_KeyValidation(t *testing.T) {
}
good := []string{
"attachments/ch/f.txt",
"attachments/channel-1/att-abc_test.pdf",
"files/ch/f.txt",
"files/channel-1/att-abc_test.pdf",
"processing/abc123/status.json",
}
for _, key := range good {
@@ -133,7 +133,7 @@ func testS3Store(t *testing.T) *S3Store {
// Clean up prefix after test
t.Cleanup(func() {
ctx := context.Background()
_ = s.DeletePrefix(ctx, "attachments")
_ = s.DeletePrefix(ctx, "files")
_ = s.DeletePrefix(ctx, "processing")
})
@@ -145,7 +145,7 @@ func TestS3_Integration_PutGetRoundTrip(t *testing.T) {
ctx := context.Background()
data := []byte("hello, S3 storage world")
key := "attachments/channel-1/att-1_test.txt"
key := "files/channel-1/att-1_test.txt"
err := s.Put(ctx, key, bytes.NewReader(data), int64(len(data)), "text/plain")
if err != nil {
@@ -175,7 +175,7 @@ func TestS3_Integration_GetNotFound(t *testing.T) {
s := testS3Store(t)
ctx := context.Background()
_, _, _, err := s.Get(ctx, "attachments/nonexistent/file.txt")
_, _, _, err := s.Get(ctx, "files/nonexistent/file.txt")
if err != ErrNotFound {
t.Errorf("err = %v, want ErrNotFound", err)
}
@@ -185,7 +185,7 @@ func TestS3_Integration_Delete(t *testing.T) {
s := testS3Store(t)
ctx := context.Background()
key := "attachments/ch/delete-me.txt"
key := "files/ch/delete-me.txt"
_ = s.Put(ctx, key, bytes.NewReader([]byte("bye")), 3, "text/plain")
err := s.Delete(ctx, key)
@@ -204,7 +204,7 @@ func TestS3_Integration_DeleteIdempotent(t *testing.T) {
ctx := context.Background()
// S3 delete is inherently idempotent
err := s.Delete(ctx, "attachments/no-such/file.txt")
err := s.Delete(ctx, "files/no-such/file.txt")
if err != nil {
t.Errorf("Delete nonexistent: %v", err)
}
@@ -214,16 +214,16 @@ func TestS3_Integration_DeletePrefix(t *testing.T) {
s := testS3Store(t)
ctx := context.Background()
prefix := "attachments/channel-abc/"
prefix := "files/channel-abc/"
for _, name := range []string{"a.txt", "b.png", "c.pdf"} {
key := prefix + name
_ = s.Put(ctx, key, bytes.NewReader([]byte("x")), 1, "text/plain")
}
other := "attachments/channel-other/keep.txt"
other := "files/channel-other/keep.txt"
_ = s.Put(ctx, other, bytes.NewReader([]byte("y")), 1, "text/plain")
err := s.DeletePrefix(ctx, "attachments/channel-abc")
err := s.DeletePrefix(ctx, "files/channel-abc")
if err != nil {
t.Fatalf("DeletePrefix: %v", err)
}
@@ -245,7 +245,7 @@ func TestS3_Integration_Exists(t *testing.T) {
s := testS3Store(t)
ctx := context.Background()
key := "attachments/ch/exists.txt"
key := "files/ch/exists.txt"
_ = s.Put(ctx, key, bytes.NewReader([]byte("hi")), 2, "text/plain")
exists, err := s.Exists(ctx, key)
@@ -256,7 +256,7 @@ func TestS3_Integration_Exists(t *testing.T) {
t.Error("Exists returned false for existing file")
}
exists, err = s.Exists(ctx, "attachments/ch/nope.txt")
exists, err = s.Exists(ctx, "files/ch/nope.txt")
if err != nil {
t.Fatalf("Exists (missing): %v", err)
}
@@ -278,7 +278,7 @@ func TestS3_Integration_Stats(t *testing.T) {
// Add some files
for i := 0; i < 3; i++ {
key := "attachments/ch/" + string(rune('a'+i)) + ".txt"
key := "files/ch/" + string(rune('a'+i)) + ".txt"
data := bytes.Repeat([]byte("x"), 100*(i+1))
_ = s.Put(ctx, key, bytes.NewReader(data), int64(len(data)), "text/plain")
}
@@ -306,7 +306,7 @@ func TestS3_Integration_PutUnknownSize(t *testing.T) {
ctx := context.Background()
data := []byte("unknown size upload")
key := "attachments/ch/unknown-size.txt"
key := "files/ch/unknown-size.txt"
// size=0 means unknown — S3 should handle via multipart
err := s.Put(ctx, key, bytes.NewReader(data), 0, "text/plain")