分站可单独配置回收、合作反馈和客服二维码,未配置时继承主站;Logo、图标和轮播支持直接上传。 Co-authored-by: Cursor <cursoragent@cursor.com>
104 lines
3.4 KiB
Go
104 lines
3.4 KiB
Go
package file
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/minio/minio-go/v7"
|
|
)
|
|
|
|
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 TestParseBucketLookup(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
raw string
|
|
want minio.BucketLookupType
|
|
}{
|
|
{name: "auto", raw: "auto", want: minio.BucketLookupAuto},
|
|
{name: "dns", raw: "dns", want: minio.BucketLookupDNS},
|
|
{name: "path", raw: "path", want: minio.BucketLookupPath},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := parseBucketLookup(tt.raw)
|
|
if err != nil || got != tt.want {
|
|
t.Fatalf("parseBucketLookup(%q) = %v, %v", tt.raw, got, err)
|
|
}
|
|
})
|
|
}
|
|
if _, err := parseBucketLookup("invalid"); err == nil {
|
|
t.Fatal("invalid bucket lookup should fail")
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
func TestCooperationFeedbackSceneUsesPublicFileURL(t *testing.T) {
|
|
if got := normalizeScene("cooperation-feedback"); got != "cooperation-feedback" {
|
|
t.Fatalf("normalize cooperation-feedback scene = %q", got)
|
|
}
|
|
key := "cooperation-feedback/2026/07/19/example.webp"
|
|
got := fileURLForScene("cooperation-feedback", key)
|
|
if !strings.HasPrefix(got, "/api/public/files/object?") {
|
|
t.Fatalf("cooperation-feedback file url = %q, want public file endpoint", got)
|
|
}
|
|
}
|
|
|
|
func TestSupportQrcodeSceneUsesPublicFileURL(t *testing.T) {
|
|
if got := normalizeScene("support-qrcode"); got != "support-qrcode" {
|
|
t.Fatalf("normalize support-qrcode scene = %q", got)
|
|
}
|
|
got := fileURLForScene("support-qrcode", "support-qrcode/2026/09/25/example.png")
|
|
if !strings.HasPrefix(got, "/api/public/files/object?") {
|
|
t.Fatalf("support-qrcode file url = %q, want public file endpoint", got)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeSceneListingScreenshotAndOperatingExpense(t *testing.T) {
|
|
if got := normalizeScene("listing_screenshot"); got != "listing" {
|
|
t.Fatalf("normalize listing_screenshot scene = %q, want listing", got)
|
|
}
|
|
if got := normalizeScene("listing-screenshot"); got != "listing" {
|
|
t.Fatalf("normalize listing-screenshot scene = %q, want listing", got)
|
|
}
|
|
if got := normalizeScene("operating-expense"); got != "operating-expense" {
|
|
t.Fatalf("normalize operating-expense scene = %q, want operating-expense", got)
|
|
}
|
|
if got := normalizeScene("operating_expense"); got != "operating-expense" {
|
|
t.Fatalf("normalize operating_expense scene = %q, want operating-expense", got)
|
|
}
|
|
}
|