Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout. Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package entity
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildObjectKeyByPurpose(t *testing.T) {
|
|
avatar := BuildObjectKey(PurposeAvatar, 11, 99, "20260917", "jpg")
|
|
if avatar != "perm/avatar/11/20260917/99.jpg" {
|
|
t.Fatalf("avatar %s", avatar)
|
|
}
|
|
chat := BuildObjectKey(PurposeChatImage, 11, 99, "20260917", "jpg")
|
|
if chat != "chat/20260917/11/99.jpg" {
|
|
t.Fatalf("chat %s", chat)
|
|
}
|
|
group := BuildObjectKey(PurposeGroupAvatar, 7, 99, "20260917", "png")
|
|
if group != "perm/group/7/99.png" {
|
|
t.Fatalf("group %s", group)
|
|
}
|
|
fav := BuildFavKey(11, 7, "20260917", "m4a")
|
|
if fav != "perm/fav/11/20260917/7.m4a" {
|
|
t.Fatalf("fav %s", fav)
|
|
}
|
|
}
|
|
|
|
func TestValidObjectKey(t *testing.T) {
|
|
if !ValidObjectKey("chat/20260917/1/2.jpg") || !ValidObjectKey("perm/avatar/1/2.jpg") || !ValidObjectKey("perm/group/3/4.jpg") {
|
|
t.Fatal("want valid")
|
|
}
|
|
for _, key := range []string{"", "../x", "/chat/a", "other/a", "chat/a b.jpg", "chat/.. /x"} {
|
|
if ValidObjectKey(key) {
|
|
t.Fatalf("accepted %q", key)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNormalizeMIMEAndExt(t *testing.T) {
|
|
if got := NormalizeMIME("Image/JPEG; charset=utf-8"); got != "image/jpeg" {
|
|
t.Fatalf("mime %s", got)
|
|
}
|
|
if ExtForMIME("image/png") != "png" || ExtOfKey("chat/a/b.M4A") != "m4a" {
|
|
t.Fatal("ext")
|
|
}
|
|
spec, ok := LookupSpec(PurposeChatVoice)
|
|
if !ok || spec.MaxSize <= 0 {
|
|
t.Fatal("spec")
|
|
}
|
|
if _, ok := spec.MIMEs["audio/mpeg"]; !ok {
|
|
t.Fatal("voice mime")
|
|
}
|
|
if strings.Contains(BuildObjectKey(PurposeAvatar, 1, 1, "d", "jpg"), PrefixChat) {
|
|
t.Fatal("avatar must be perm")
|
|
}
|
|
}
|