fix: handle opaque attachment references
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tinode/chat/server/store/types"
|
||||
)
|
||||
|
||||
func TestFileLinkUserIDAllowsOpaqueTopicReferences(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
topic string
|
||||
isUser bool
|
||||
wantUID types.Uid
|
||||
}{
|
||||
{name: "cultivate reference", topic: "cvpbzxw1aio4ni8x0"},
|
||||
{name: "short opaque reference", topic: "x"},
|
||||
{name: "empty reference", topic: ""},
|
||||
{name: "user reference", topic: types.Uid(42).UserId(), isUser: true, wantUID: types.Uid(42)},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
gotUID, gotIsUser := fileLinkUserID(test.topic)
|
||||
if gotIsUser != test.isUser || gotUID != test.wantUID {
|
||||
t.Fatalf("fileLinkUserID(%q) = (%v, %v), want (%v, %v)", test.topic, gotUID, gotIsUser, test.wantUID, test.isUser)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user