mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-23 19:12:00 -08:00
8798ff6fc1
- Fixed commands from v 0.4.0 and tests - Added primitive Result Sets support (XEP-0059)
41 lines
2.0 KiB
Go
41 lines
2.0 KiB
Go
package stanza_test
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"gosrc.io/xmpp/stanza"
|
|
"testing"
|
|
)
|
|
|
|
func TestMarshalCommands(t *testing.T) {
|
|
input := "<command xmlns=\"http://jabber.org/protocol/commands\" node=\"list\" " +
|
|
"sessionid=\"list:20020923T213616Z-700\" status=\"completed\"><x xmlns=\"jabber:x:data\" " +
|
|
"type=\"result\"><title>Available Services</title><reported xmlns=\"jabber:x:data\"><field var=\"service\" " +
|
|
"label=\"Service\"></field><field var=\"runlevel-1\" label=\"Single-User mode\">" +
|
|
"</field><field var=\"runlevel-2\" label=\"Non-Networked Multi-User mode\"></field><field var=\"runlevel-3\" " +
|
|
"label=\"Full Multi-User mode\"></field><field var=\"runlevel-5\" label=\"X-Window mode\"></field></reported>" +
|
|
"<item xmlns=\"jabber:x:data\"><field var=\"service\"><value>httpd</value></field><field var=\"runlevel-1\">" +
|
|
"<value>off</value></field><field var=\"runlevel-2\"><value>off</value></field><field var=\"runlevel-3\">" +
|
|
"<value>on</value></field><field var=\"runlevel-5\"><value>on</value></field></item>" +
|
|
"<item xmlns=\"jabber:x:data\"><field var=\"service\"><value>postgresql</value></field>" +
|
|
"<field var=\"runlevel-1\"><value>off</value></field><field var=\"runlevel-2\"><value>off</value></field>" +
|
|
"<field var=\"runlevel-3\"><value>on</value></field><field var=\"runlevel-5\"><value>on</value></field></item>" +
|
|
"<item xmlns=\"jabber:x:data\"><field var=\"service\"><value>jabberd</value></field><field var=\"runlevel-1\">" +
|
|
"<value>off</value></field><field var=\"runlevel-2\"><value>off</value></field><field var=\"runlevel-3\">" +
|
|
"<value>on</value></field><field var=\"runlevel-5\"><value>on</value></field></item></x></command>"
|
|
var c stanza.Command
|
|
err := xml.Unmarshal([]byte(input), &c)
|
|
|
|
if err != nil {
|
|
t.Fatalf("failed to unmarshal initial input")
|
|
}
|
|
|
|
data, err := xml.Marshal(c)
|
|
if err != nil {
|
|
t.Fatalf("failed to marshal unmarshalled input")
|
|
}
|
|
|
|
if err := compareMarshal(input, string(data)); err != nil {
|
|
t.Fatalf(err.Error())
|
|
}
|
|
}
|