mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-22 02:22:00 -08:00
8798ff6fc1
- Fixed commands from v 0.4.0 and tests - Added primitive Result Sets support (XEP-0059)
34 lines
773 B
Go
34 lines
773 B
Go
package stanza
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"testing"
|
|
)
|
|
|
|
func TestNode_Marshal(t *testing.T) {
|
|
jsonData := []byte("{\"key\":\"value\"}")
|
|
|
|
iqResp, err := NewIQ(Attrs{Type: "result", From: "admin@localhost", To: "test@localhost", Id: "1"})
|
|
if err != nil {
|
|
t.Fatalf("failed to create IQ: %v", err)
|
|
}
|
|
iqResp.Any = &Node{
|
|
XMLName: xml.Name{Space: "myNS", Local: "space"},
|
|
Content: string(jsonData),
|
|
}
|
|
|
|
bytes, err := xml.Marshal(iqResp)
|
|
if err != nil {
|
|
t.Errorf("Could not marshal XML: %v", err)
|
|
}
|
|
|
|
parsedIQ := IQ{}
|
|
if err := xml.Unmarshal(bytes, &parsedIQ); err != nil {
|
|
t.Errorf("Unmarshal returned error: %v", err)
|
|
}
|
|
|
|
if parsedIQ.Any.Content != string(jsonData) {
|
|
t.Errorf("Cannot find generic any payload in parsedIQ: '%s'", parsedIQ.Any.Content)
|
|
}
|
|
}
|