Add helpers for IQ DiscoItems

This commit is contained in:
Mickael Remond
2019-07-09 16:59:54 +02:00
parent 79803a8af9
commit 026e5e6fe1
3 changed files with 95 additions and 13 deletions
+25
View File
@@ -2,10 +2,35 @@ package stanza_test
import (
"encoding/xml"
"testing"
"github.com/google/go-cmp/cmp"
"gosrc.io/xmpp/stanza"
)
// ============================================================================
// Marshaller / unmarshaller test
func marshallUnmarshall(t *testing.T, iq stanza.IQ) (*stanza.IQ, error) {
// Marshall
data, err := xml.Marshal(iq)
if err != nil {
t.Errorf("cannot marshal iq: %s\n%#v", err, iq)
return nil, err
}
// Unmarshall
var parsedIQ stanza.IQ
err = xml.Unmarshal(data, &parsedIQ)
if err != nil {
t.Errorf("Unmarshal returned error: %s\n%s", err, data)
}
return &parsedIQ, err
}
// ============================================================================
// XML structs comparison
// Compare iq structure but ignore empty namespace as they are set properly on
// marshal / unmarshal. There is no need to manage them on the manually
// crafted structure.