package badger import ( "reflect" "testing" ) func TestToKeyPrefix(t *testing.T) { if !reflect.DeepEqual(toKeyPrefix("+123456789", "test@example.com"), []byte("+123456789/test@example.com/")) { t.Error("Wrong prefix") } } func TestToByteKey(t *testing.T) { if !reflect.DeepEqual(toByteKey([]byte("ababa/galamaga/"), []byte("123"), "ppp"), []byte("ababa/galamaga/ppp/123")) { t.Error("Wrong key") } } func TestToTgByteString(t *testing.T) { if !reflect.DeepEqual(toTgByteString(-2345, 6789), []byte("-2345/6789")) { t.Error("Wrong tg string") } } func TestToXmppByteString(t *testing.T) { if !reflect.DeepEqual(toXmppByteString("aboba"), []byte("aboba")) { t.Error("Wrong xmpp string") } } func TestSplitTgByteStringUnparsable(t *testing.T) { _, _, err := splitTgByteString([]byte("@#U*&$(@#")) if err == nil { t.Error("Unparsable should not be parsed") return } if err.Error() != "Couldn't parse tg id pair" { t.Error("Wrong parse error") } } func TestSplitTgByteManyParts(t *testing.T) { _, _, err := splitTgByteString([]byte("a/b/c/d")) if err == nil { t.Error("Should not parse many parts") return } if err.Error() != "Couldn't parse tg id pair" { t.Error("Wrong parse error") } } func TestSplitTgByteNonNumeric(t *testing.T) { _, _, err := splitTgByteString([]byte("0/a")) if err == nil { t.Error("Should not parse non-numeric msgid") } } func TestSplitTgByteSuccess(t *testing.T) { chatId, msgId, err := splitTgByteString([]byte("-198282398/23798478")) if err != nil { t.Error("Should be parsed well") } if chatId != -198282398 { t.Error("Wrong chatId") } if msgId != 23798478 { t.Error("Wrong msgId") } }