2018-12-26 09:50:01 -08:00
|
|
|
package xmpp // import "gosrc.io/xmpp"
|
2016-01-06 08:59:44 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-01-06 10:21:37 -08:00
|
|
|
func TestValidJids(t *testing.T) {
|
2016-01-06 08:59:44 -08:00
|
|
|
var jid *Jid
|
|
|
|
var err error
|
|
|
|
|
2016-01-06 10:21:37 -08:00
|
|
|
goodJids := []string{"test@domain.com", "test@domain.com/resource"}
|
2016-01-06 08:59:44 -08:00
|
|
|
|
2016-01-06 10:21:37 -08:00
|
|
|
for i, sjid := range goodJids {
|
|
|
|
if jid, err = NewJid(sjid); err != nil {
|
|
|
|
t.Error("could not parse correct jid")
|
|
|
|
}
|
2016-01-06 08:59:44 -08:00
|
|
|
|
2016-01-06 10:21:37 -08:00
|
|
|
if jid.username != "test" {
|
|
|
|
t.Error("incorrect jid username")
|
|
|
|
}
|
|
|
|
|
|
|
|
if jid.domain != "domain.com" {
|
|
|
|
t.Error("incorrect jid domain")
|
|
|
|
}
|
2016-01-06 08:59:44 -08:00
|
|
|
|
2016-01-06 10:21:37 -08: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 08:59:44 -08:00
|
|
|
}
|
2016-01-06 10:21:37 -08: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 08:59:44 -08:00
|
|
|
|
2016-01-06 10:21:37 -08:00
|
|
|
for _, sjid := range badJids {
|
|
|
|
if _, err := NewJid(sjid); err == nil {
|
|
|
|
t.Error("parsing incorrect jid should return error: " + sjid)
|
|
|
|
}
|
2016-01-06 08:59:44 -08:00
|
|
|
}
|
|
|
|
}
|