From 322a6594e7f9393abaf3520bf2d6499fa3827b1f Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Mon, 10 Jun 2019 12:30:01 +0200 Subject: [PATCH] Fix missing entry in payload registry --- iq.go | 18 +++++++++++------- iq_test.go | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/iq.go b/iq.go index 92a9a19..d69df71 100644 --- a/iq.go +++ b/iq.go @@ -317,13 +317,6 @@ type DiscoItem struct { 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) @@ -335,3 +328,14 @@ type Version struct { Version string `xml:"version,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{}) +} diff --git a/iq_test.go b/iq_test.go index eb3ab2a..fc9e921 100644 --- a/iq_test.go +++ b/iq_test.go @@ -1,4 +1,4 @@ -package xmpp_test // import "gosrc.io/xmpp" +package xmpp_test // import "gosrc.io/xmpp_test" import ( "encoding/xml" @@ -113,3 +113,17 @@ func TestDiscoItems(t *testing.T) { t.Errorf("non matching items\n%s", cmp.Diff(parsedIQ.Payload, iq.Payload)) } } + +func TestUnmarshalPayload(t *testing.T) { + query := "" + + 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)) + } +}