go-xmpp/xmpp/jid_test.go

47 lines
947 B
Go
Raw Normal View History

2016-01-06 16:59:44 +00:00
package xmpp
import (
"testing"
)
2016-01-06 18:21:37 +00:00
func TestValidJids(t *testing.T) {
2016-01-06 16:59:44 +00:00
var jid *Jid
var err error
2016-01-06 18:21:37 +00:00
goodJids := []string{"test@domain.com", "test@domain.com/resource"}
2016-01-06 16:59:44 +00:00
2016-01-06 18:21:37 +00:00
for i, sjid := range goodJids {
if jid, err = NewJid(sjid); err != nil {
t.Error("could not parse correct jid")
}
2016-01-06 16:59:44 +00:00
2016-01-06 18:21:37 +00:00
if jid.username != "test" {
t.Error("incorrect jid username")
}
if jid.domain != "domain.com" {
t.Error("incorrect jid domain")
}
2016-01-06 16:59:44 +00:00
2016-01-06 18:21:37 +00:00
if i == 0 && jid.resource != "" {
t.Error("bare jid resource should be empty")
}
if i == 1 && jid.resource != "resource" {
t.Error("incorrect full jid resource")
}
2016-01-06 16:59:44 +00:00
}
2016-01-06 18:21:37 +00:00
}
// TODO: Check if resource cannot contain a /
func TestIncorrectJids(t *testing.T) {
badJids := []string{"test@domain.com@otherdomain.com",
"test@domain.com/test/test"}
2016-01-06 16:59:44 +00:00
2016-01-06 18:21:37 +00:00
for _, sjid := range badJids {
if _, err := NewJid(sjid); err == nil {
t.Error("parsing incorrect jid should return error: " + sjid)
}
2016-01-06 16:59:44 +00:00
}
}