|
|
@ -7,29 +7,21 @@ import (
|
|
|
|
"gosrc.io/xmpp/stanza"
|
|
|
|
"gosrc.io/xmpp/stanza"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestDiscoInfoBuilder(t *testing.T) {
|
|
|
|
func TestDiscoInfo_Builder(t *testing.T) {
|
|
|
|
iq := stanza.NewIQ(stanza.Attrs{Type: "get", To: "service.localhost", Id: "disco-get-1"})
|
|
|
|
iq := stanza.NewIQ(stanza.Attrs{Type: "get", To: "service.localhost", Id: "disco-get-1"})
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
|
|
|
// Marshall
|
|
|
|
parsedIQ, err := marshallUnmarshall(t, iq)
|
|
|
|
data, err := xml.Marshal(iq)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("cannot marshal xml structure: %s", err)
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Unmarshall
|
|
|
|
|
|
|
|
var parsedIQ stanza.IQ
|
|
|
|
|
|
|
|
if err = xml.Unmarshal(data, &parsedIQ); err != nil {
|
|
|
|
|
|
|
|
t.Errorf("Unmarshal(%s) returned error: %s", data, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check result
|
|
|
|
// Check result
|
|
|
|
pp, ok := parsedIQ.Payload.(*stanza.DiscoInfo)
|
|
|
|
pp, ok := parsedIQ.Payload.(*stanza.DiscoInfo)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
t.Errorf("Parsed stanza does not contain an IQ payload")
|
|
|
|
t.Errorf("Parsed stanza does not contain correct IQ payload")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check features
|
|
|
|
// Check features
|
|
|
@ -53,3 +45,39 @@ func TestDiscoInfoBuilder(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Implements XEP-0030 example 17
|
|
|
|
|
|
|
|
// https://xmpp.org/extensions/xep-0030.html#example-17
|
|
|
|
|
|
|
|
func TestDiscoItems_Builder(t *testing.T) {
|
|
|
|
|
|
|
|
iq := stanza.NewIQ(stanza.Attrs{Type: "result", From: "catalog.shakespeare.lit",
|
|
|
|
|
|
|
|
To: "romeo@montague.net/orchard", Id: "items-2"})
|
|
|
|
|
|
|
|
iq.DiscoItems().
|
|
|
|
|
|
|
|
AddItem("catalog.shakespeare.lit", "books", "Books by and about Shakespeare").
|
|
|
|
|
|
|
|
AddItem("catalog.shakespeare.lit", "clothing", "Wear your literary taste with pride").
|
|
|
|
|
|
|
|
AddItem("catalog.shakespeare.lit", "music", "Music from the time of Shakespeare")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parsedIQ, err := marshallUnmarshall(t, iq)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check result
|
|
|
|
|
|
|
|
pp, ok := parsedIQ.Payload.(*stanza.DiscoItems)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
t.Errorf("Parsed stanza does not contain correct IQ payload")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check items
|
|
|
|
|
|
|
|
items := []stanza.DiscoItem{{xml.Name{}, "catalog.shakespeare.lit", "books", "Books by and about Shakespeare"},
|
|
|
|
|
|
|
|
{xml.Name{}, "catalog.shakespeare.lit", "clothing", "Wear your literary taste with pride"},
|
|
|
|
|
|
|
|
{xml.Name{}, "catalog.shakespeare.lit", "music", "Music from the time of Shakespeare"}}
|
|
|
|
|
|
|
|
if len(pp.Items) != len(items) {
|
|
|
|
|
|
|
|
t.Errorf("Items length mismatch: %#v", pp.Items)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for i, item := range pp.Items {
|
|
|
|
|
|
|
|
if item.JID != items[i].JID {
|
|
|
|
|
|
|
|
t.Errorf("JID Mismatch (expected: %s): %s", items[i].JID, item.JID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|