43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package file
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitizeObjectMetadataEscapesNonASCII(t *testing.T) {
|
|
got := sanitizeObjectMetadata(map[string]string{
|
|
"original-filename": "游戏ID截图 1.png",
|
|
})
|
|
|
|
if got["original-filename"] != "%E6%B8%B8%E6%88%8FID%E6%88%AA%E5%9B%BE+1.png" {
|
|
t.Fatalf("metadata filename = %q", got["original-filename"])
|
|
}
|
|
}
|
|
|
|
func TestAnnouncementSceneUsesPublicFileURL(t *testing.T) {
|
|
key := "announcement/2026/06/15/example.webp"
|
|
got := fileURLForScene("announcement", key)
|
|
|
|
if !strings.HasPrefix(got, "/api/public/files/object?") {
|
|
t.Fatalf("announcement file url = %q, want public file endpoint", got)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeSceneAllowsAnnouncement(t *testing.T) {
|
|
if got := normalizeScene("announcement"); got != "announcement" {
|
|
t.Fatalf("normalize announcement scene = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestAWRecycleSceneUsesPublicFileURL(t *testing.T) {
|
|
if got := normalizeScene("aw-recycle"); got != "aw-recycle" {
|
|
t.Fatalf("normalize aw-recycle scene = %q", got)
|
|
}
|
|
key := "aw-recycle/2026/07/19/example.webp"
|
|
got := fileURLForScene("aw-recycle", key)
|
|
if !strings.HasPrefix(got, "/api/public/files/object?") {
|
|
t.Fatalf("aw-recycle file url = %q, want public file endpoint", got)
|
|
}
|
|
}
|