go-xmpp/iq_test.go

30 lines
1.0 KiB
Go
Raw Normal View History

2018-01-01 09:12:33 -08:00
package xmpp // import "fluux.io/xmpp"
2016-02-15 09:33:51 -08:00
import (
"encoding/xml"
"reflect"
"testing"
)
func TestUnmarshalIqs(t *testing.T) {
2017-10-04 13:51:28 -07:00
//var cs1 = new(iot.ControlSet)
2016-02-15 09:33:51 -08:00
var tests = []struct {
iqString string
parsedIQ ClientIQ
}{
2018-01-13 08:54:07 -08:00
{"<iq id=\"1\" type=\"set\" to=\"test@localhost\"/>", ClientIQ{XMLName: xml.Name{Space: "", Local: "iq"}, PacketAttrs: PacketAttrs{To: "test@localhost", Type: "set", Id: "1"}}},
//{"<iq xmlns=\"jabber:client\" id=\"2\" type=\"set\" to=\"test@localhost\" from=\"server\"><set xmlns=\"urn:xmpp:iot:control\"/></iq>", ClientIQ{XMLName: xml.Name{Space: "jabber:client", Local: "iq"}, PacketAttrs: PacketAttrs{To: "test@localhost", From: "server", Type: "set", Id: "2"}, Payload: cs1}},
2016-02-15 09:33:51 -08:00
}
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)
}
}
}