forked from jshiffer/go-xmpp
Clean-up / Consistency
This commit is contained in:
parent
993ca630f7
commit
bbfafbb32c
2
iq.go
2
iq.go
@ -105,7 +105,7 @@ func (iqDecoder) decode(p *xml.Decoder, se xml.StartElement) (IQ, error) {
|
|||||||
// UnmarshalXML implements custom parsing for IQs
|
// UnmarshalXML implements custom parsing for IQs
|
||||||
func (iq *IQ) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
func (iq *IQ) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
iq.XMLName = start.Name
|
iq.XMLName = start.Name
|
||||||
fmt.Println("IQ Name", iq.XMLName)
|
|
||||||
// Extract IQ attributes
|
// Extract IQ attributes
|
||||||
for _, attr := range start.Attr {
|
for _, attr := range start.Attr {
|
||||||
if attr.Name.Local == "id" {
|
if attr.Name.Local == "id" {
|
||||||
|
15
iq_test.go
15
iq_test.go
@ -2,7 +2,6 @@ package xmpp // import "fluux.io/xmpp"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
@ -19,14 +18,16 @@ func TestUnmarshalIqs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
var parsedIQ = new(IQ)
|
parsedIQ := IQ{}
|
||||||
err := xml.Unmarshal([]byte(test.iqString), parsedIQ)
|
err := xml.Unmarshal([]byte(test.iqString), &parsedIQ)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unmarshal(%s) returned error", test.iqString)
|
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)
|
if !xmlEqual(parsedIQ, test.parsedIQ) {
|
||||||
|
t.Errorf("non matching items\n%s", cmp.Diff(parsedIQ, test.parsedIQ))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +51,8 @@ func TestGenerateIq(t *testing.T) {
|
|||||||
t.Errorf("cannot marshal xml structure")
|
t.Errorf("cannot marshal xml structure")
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsedIQ = new(IQ)
|
parsedIQ := IQ{}
|
||||||
if err = xml.Unmarshal(data, parsedIQ); err != nil {
|
if err = xml.Unmarshal(data, &parsedIQ); err != nil {
|
||||||
t.Errorf("Unmarshal(%s) returned error", data)
|
t.Errorf("Unmarshal(%s) returned error", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user