Fix missing entry in payload registry

This commit is contained in:
Mickael Remond 2019-06-10 12:30:01 +02:00
parent 45cb2e6f34
commit 322a6594e7
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3
2 changed files with 26 additions and 8 deletions

18
iq.go
View File

@ -317,13 +317,6 @@ type DiscoItem struct {
Node string `xml:"node,attr,omitempty"` Node string `xml:"node,attr,omitempty"`
} }
func init() {
TypeRegistry.MapExtension(PKTIQ, xml.Name{NSDiscoInfo, "query"}, DiscoInfo{})
TypeRegistry.MapExtension(PKTIQ, xml.Name{NSDiscoItems, "query"}, DiscoItems{})
TypeRegistry.MapExtension(PKTIQ, xml.Name{"urn:ietf:params:xml:ns:xmpp-bind", "bind"}, BindBind{})
TypeRegistry.MapExtension(PKTIQ, xml.Name{"urn:xmpp:iot:control", "set"}, ControlSet{})
}
// ============================================================================ // ============================================================================
// Software Version (XEP-0092) // Software Version (XEP-0092)
@ -335,3 +328,14 @@ type Version struct {
Version string `xml:"version,omitempty"` Version string `xml:"version,omitempty"`
OS string `xml:"os,omitempty"` OS string `xml:"os,omitempty"`
} }
// ============================================================================
// Registry init
func init() {
TypeRegistry.MapExtension(PKTIQ, xml.Name{NSDiscoInfo, "query"}, DiscoInfo{})
TypeRegistry.MapExtension(PKTIQ, xml.Name{NSDiscoItems, "query"}, DiscoItems{})
TypeRegistry.MapExtension(PKTIQ, xml.Name{"urn:ietf:params:xml:ns:xmpp-bind", "bind"}, BindBind{})
TypeRegistry.MapExtension(PKTIQ, xml.Name{"urn:xmpp:iot:control", "set"}, ControlSet{})
TypeRegistry.MapExtension(PKTIQ, xml.Name{"jabber:iq:version", "query"}, Version{})
}

View File

@ -1,4 +1,4 @@
package xmpp_test // import "gosrc.io/xmpp" package xmpp_test // import "gosrc.io/xmpp_test"
import ( import (
"encoding/xml" "encoding/xml"
@ -113,3 +113,17 @@ func TestDiscoItems(t *testing.T) {
t.Errorf("non matching items\n%s", cmp.Diff(parsedIQ.Payload, iq.Payload)) t.Errorf("non matching items\n%s", cmp.Diff(parsedIQ.Payload, iq.Payload))
} }
} }
func TestUnmarshalPayload(t *testing.T) {
query := "<iq to='service.localhost' type='get' id='1'><query xmlns='jabber:iq:version'/></iq>"
parsedIQ := xmpp.IQ{}
err := xml.Unmarshal([]byte(query), &parsedIQ)
if err != nil {
t.Errorf("Unmarshal(%s) returned error", query)
}
if len(parsedIQ.Payload) != 1 {
t.Errorf("Incorrect payload size: %d", len(parsedIQ.Payload))
}
}