package xmpp_test import ( "encoding/xml" "strings" "testing" "github.com/google/go-cmp/cmp" "gosrc.io/xmpp" ) func TestUnmarshalIqs(t *testing.T) { //var cs1 = new(iot.ControlSet) var tests = []struct { iqString string parsedIQ xmpp.IQ }{ {"", xmpp.IQ{XMLName: xml.Name{Space: "", Local: "iq"}, PacketAttrs: xmpp.PacketAttrs{To: "test@localhost", Type: "set", Id: "1"}}}, //{"", IQ{XMLName: xml.Name{Space: "jabber:client", Local: "iq"}, PacketAttrs: PacketAttrs{To: "test@localhost", From: "server", Type: "set", Id: "2"}, Payload: cs1}}, } for _, test := range tests { parsedIQ := xmpp.IQ{} err := xml.Unmarshal([]byte(test.iqString), &parsedIQ) if err != nil { t.Errorf("Unmarshal(%s) returned error", test.iqString) } if !xmlEqual(parsedIQ, test.parsedIQ) { t.Errorf("non matching items\n%s", cmp.Diff(parsedIQ, test.parsedIQ)) } } } func TestGenerateIq(t *testing.T) { iq := xmpp.NewIQ("result", "admin@localhost", "test@localhost", "1", "en") payload := xmpp.DiscoInfo{ Identity: xmpp.Identity{ Name: "Test Gateway", Category: "gateway", Type: "mqtt", }, Features: []xmpp.Feature{ {Var: xmpp.NSDiscoInfo}, {Var: xmpp.NSDiscoItems}, }, } iq.Payload = &payload data, err := xml.Marshal(iq) if err != nil { t.Errorf("cannot marshal xml structure") } if strings.Contains(string(data), "