42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package store
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/tinode/chat/server/store/types"
|
|
)
|
|
|
|
func TestForTenantRejectsZero(t *testing.T) {
|
|
if scoped, err := ForTenant(types.ZeroTenantID); err != types.ErrMalformed || scoped != nil {
|
|
t.Fatalf("ForTenant(0) = (%v, %v), want (nil, malformed)", scoped, err)
|
|
}
|
|
}
|
|
|
|
func TestValidateMessageHeadersProductContract(t *testing.T) {
|
|
valid := []types.KVMap{
|
|
{"x-im-schema": float64(1), "x-im-type": "text"},
|
|
{"x-im-schema": json.Number("1"), "x-im-type": "voice"},
|
|
{"x-im-schema": "1", "x-im-type": "contact_card"},
|
|
{"x-im-schema": 1, "type": "audio", "x-im-type": "voice"},
|
|
{"type": "system"},
|
|
}
|
|
for _, head := range valid {
|
|
if err := validateMessageHeaders(head); err != nil {
|
|
t.Fatalf("validateMessageHeaders(%v) = %v, want nil", head, err)
|
|
}
|
|
}
|
|
|
|
invalid := []types.KVMap{
|
|
{"x-im-schema": float64(2), "x-im-type": "text"},
|
|
{"x-im-schema": true, "x-im-type": "text"},
|
|
{"x-im-schema": float64(1), "x-im-type": "unknown"},
|
|
{"type": "text", "x-im-type": "image"},
|
|
}
|
|
for _, head := range invalid {
|
|
if err := validateMessageHeaders(head); err != types.ErrMalformed {
|
|
t.Fatalf("validateMessageHeaders(%v) = %v, want malformed", head, err)
|
|
}
|
|
}
|
|
}
|