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, 1<<20); v != nil {
|
|
t.Fatalf("expected ok, got %+v", v)
|
|
}
|
|
if v := p.CheckImageMeta(2000, 1000, 1<<20); v == nil || v.Reason != "edge_exceeded" {
|
|
t.Fatalf("want edge_exceeded, got %+v", v)
|
|
}
|
|
if v := p.CheckImageMeta(800, 600, 20<<20); v == nil || v.Reason != "size_exceeded" {
|
|
t.Fatalf("want size_exceeded, 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")
|
|
}
|
|
}
|