Compare commits

...

3 commits

4 changed files with 53 additions and 17 deletions

View file

@ -21,6 +21,7 @@ type DiscoInfo struct {
Identity []Identity `xml:"identity"` Identity []Identity `xml:"identity"`
Features []Feature `xml:"feature"` Features []Feature `xml:"feature"`
ResultSet *ResultSet `xml:"set,omitempty"` ResultSet *ResultSet `xml:"set,omitempty"`
Form *Form `xml:"x,omitempty"`
} }
// Namespace lets DiscoInfo implement the IQPayload interface // Namespace lets DiscoInfo implement the IQPayload interface

View file

@ -16,6 +16,7 @@ func TestDiscoInfo_Builder(t *testing.T) {
disco := iq.DiscoInfo() disco := iq.DiscoInfo()
disco.AddIdentity("Test Component", "gateway", "service") disco.AddIdentity("Test Component", "gateway", "service")
disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1") disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1")
disco.Form = stanza.NewForm([]*stanza.Field{}, "result")
parsedIQ, err := checkMarshalling(t, iq) parsedIQ, err := checkMarshalling(t, iq)
if err != nil { if err != nil {
@ -48,6 +49,15 @@ func TestDiscoInfo_Builder(t *testing.T) {
t.Errorf("Incorrect identity name: %#v", pp.Identity[0].Name) t.Errorf("Incorrect identity name: %#v", pp.Identity[0].Name)
} }
} }
// Check form
if pp.Form == nil {
t.Errorf("Form is nil")
} else {
if len(pp.Form.Fields) != 0 {
t.Errorf("Form fields length mismatch: %#v", pp.Form.Fields)
}
}
} }
// Implements XEP-0030 example 17 // Implements XEP-0030 example 17

View file

@ -51,11 +51,21 @@ func NewJid(sjid string) (*Jid, error) {
} }
func (j *Jid) Full() string { func (j *Jid) Full() string {
if j.Resource == "" {
return j.Bare()
} else if j.Node == "" {
return j.Node + "/" + j.Resource
} else {
return j.Node + "@" + j.Domain + "/" + j.Resource return j.Node + "@" + j.Domain + "/" + j.Resource
}
} }
func (j *Jid) Bare() string { func (j *Jid) Bare() string {
if j.Node == "" {
return j.Domain
} else {
return j.Node + "@" + j.Domain return j.Node + "@" + j.Domain
}
} }
// ============================================================================ // ============================================================================

View file

@ -61,26 +61,41 @@ func TestIncorrectJids(t *testing.T) {
} }
func TestFull(t *testing.T) { func TestFull(t *testing.T) {
jid := "test@domain.com/my resource" fullJids := []string{
parsedJid, err := NewJid(jid) "test@domain.com/my resource",
"test@domain.com",
"domain.com",
}
for _, sjid := range fullJids {
parsedJid, err := NewJid(sjid)
if err != nil { if err != nil {
t.Errorf("could not parse jid: %v", err) t.Errorf("could not parse jid: %v", err)
} }
fullJid := parsedJid.Full() fullJid := parsedJid.Full()
if fullJid != jid { if fullJid != sjid {
t.Errorf("incorrect full jid: %s", fullJid) t.Errorf("incorrect full jid: %s", fullJid)
} }
}
} }
func TestBare(t *testing.T) { func TestBare(t *testing.T) {
jid := "test@domain.com" tests := []struct {
fullJid := jid + "/my resource" jidstr string
parsedJid, err := NewJid(fullJid) expected string
}{
{jidstr: "test@domain.com", expected: "test@domain.com"},
{jidstr: "test@domain.com/resource", expected: "test@domain.com"},
{jidstr: "domain.com", expected: "domain.com"},
}
for _, tt := range tests {
parsedJid, err := NewJid(tt.jidstr)
if err != nil { if err != nil {
t.Errorf("could not parse jid: %v", err) t.Errorf("could not parse jid: %v", err)
} }
bareJid := parsedJid.Bare() bareJid := parsedJid.Bare()
if bareJid != jid { if bareJid != tt.expected {
t.Errorf("incorrect bare jid: %s", bareJid) t.Errorf("incorrect bare jid: %s", bareJid)
} }
}
} }