管理端按用户查询开启通讯录/相册/媒体拉取;服务端写入路径自动压图;新增 /v1/sign 与 /v1/energy。 Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package media
|
|
|
|
import "testing"
|
|
|
|
func TestCheckImageMeta(t *testing.T) {
|
|
p := Policy{Enabled: true, Limits: DefaultLimits()}
|
|
if v := p.CheckImageMeta(1080, 720, 100<<10); v != nil {
|
|
t.Fatalf("expected ok under 150KiB, got %+v", v)
|
|
}
|
|
if v := p.CheckImageMeta(2000, 1000, 100<<10); v == nil || v.Reason != "edge_exceeded" {
|
|
t.Fatalf("want edge_exceeded, got %+v", v)
|
|
}
|
|
if v := p.CheckImageMeta(800, 600, 200<<10); v == nil || v.Reason != "size_exceeded" {
|
|
t.Fatalf("want size_exceeded (>150KiB), got %+v", v)
|
|
}
|
|
p.Enabled = false
|
|
if v := p.CheckImageMeta(4000, 4000, 50<<20); v != nil {
|
|
t.Fatalf("disabled should skip, got %+v", v)
|
|
}
|
|
}
|
|
|
|
func TestCheckVideoAndAvatar(t *testing.T) {
|
|
p := Policy{Enabled: true, Limits: DefaultLimits()}
|
|
if v := p.CheckVideoMeta(1280, 720, 10<<20, 5000); v == nil || v.Reason != "edge_exceeded" {
|
|
t.Fatalf("1280 edge should fail vs 720: %+v", v)
|
|
}
|
|
if v := p.CheckVideoMeta(720, 480, 10<<20, 5000); v != nil {
|
|
t.Fatalf("720p ok: %+v", v)
|
|
}
|
|
if v := p.CheckAvatarMeta(200, 200, 100<<10); v != nil {
|
|
t.Fatalf("avatar ok: %+v", v)
|
|
}
|
|
if v := p.CheckAvatarMeta(400, 400, 100<<10); v == nil {
|
|
t.Fatal("avatar 400 should fail")
|
|
}
|
|
}
|
|
|
|
func TestNeedsResize(t *testing.T) {
|
|
if NeedsResize(1080, 720, 1080) {
|
|
t.Fatal("equal edge should not resize")
|
|
}
|
|
if !NeedsResize(1081, 1, 1080) {
|
|
t.Fatal("want resize")
|
|
}
|
|
}
|