Add more test on jid parsing

This commit is contained in:
Mickael Remond 2016-01-06 19:21:37 +01:00
parent f7651c7785
commit 5949967daf

View File

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