go-xmpp/jid_test.go

52 lines
1 KiB
Go
Raw Normal View History

package xmpp // import "gosrc.io/xmpp"
2016-01-06 16:59:44 +00:00
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")
2019-06-04 17:01:19 +00:00
return
}
if jid == nil {
t.Error("jid should not be nil")
2016-01-06 18:21:37 +00:00
}
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
}
}