Fix missing type on IQ
This commit is contained in:
parent
6fdef748be
commit
e6a645dee0
|
@ -29,6 +29,9 @@ func (iq *ClientIQ) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
if attr.Name.Local == "id" {
|
if attr.Name.Local == "id" {
|
||||||
iq.Id = attr.Value
|
iq.Id = attr.Value
|
||||||
}
|
}
|
||||||
|
if attr.Name.Local == "type" {
|
||||||
|
iq.Type = attr.Value
|
||||||
|
}
|
||||||
if attr.Name.Local == "to" {
|
if attr.Name.Local == "to" {
|
||||||
iq.To = attr.Value
|
iq.To = attr.Value
|
||||||
}
|
}
|
||||||
|
@ -75,6 +78,8 @@ func (iq *ClientIQ) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XMPPFormat returns the string representation of the XMPP packet.
|
||||||
|
// TODO: Should I simply rely on xml.Marshal ?
|
||||||
func (iq *ClientIQ) XMPPFormat() string {
|
func (iq *ClientIQ) XMPPFormat() string {
|
||||||
if iq.Payload != nil {
|
if iq.Payload != nil {
|
||||||
var payload []byte
|
var payload []byte
|
||||||
|
|
27
xmpp/iq_test.go
Normal file
27
xmpp/iq_test.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package xmpp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUnmarshalIqs(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
iqString string
|
||||||
|
parsedIQ ClientIQ
|
||||||
|
}{
|
||||||
|
{"<iq id=\"1\" type=\"set\" to=\"test@localhost\"/>", ClientIQ{XMLName: xml.Name{Space: "", Local: "iq"}, Packet: Packet{To: "test@localhost", Type: "set", Id: "1"}}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
var parsedIQ = new(ClientIQ)
|
||||||
|
err := xml.Unmarshal([]byte(test.iqString), parsedIQ)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unmarshal(%s) returned error", test.iqString)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(parsedIQ, &test.parsedIQ) {
|
||||||
|
t.Errorf("Unmarshal(%s) expecting result %+v = %+v", test.iqString, parsedIQ, &test.parsedIQ)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue