-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
39 lines (36 loc) · 1.08 KB
/
response_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package netconf
import (
"testing"
"github.com/freeconf/yang/fc"
"github.com/freeconf/yang/nodeutil"
"github.com/freeconf/yang/patch/xml"
)
func TestXmlWriter(t *testing.T) {
tests := []struct {
msg any
expected string
}{
{
msg: &HelloMsg{
Capabilities: []*Msg{
{Content: "xyz"},
},
SessionId: "99",
},
expected: `<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><capabilities><capability>xyz</capability></capabilities><session-id>99</session-id></hello>`,
},
{
msg: &RpcReply{MessageId: "abc", OK: &Msg{}},
expected: `<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="abc"><ok></ok></rpc-reply>`,
},
{
msg: &RpcReply{MessageId: "abc", Out: []*nodeutil.XMLWtr2{{XMLName: xml.Name{Local: "foo", Space: "bar"}}}},
expected: `<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="abc"><foo xmlns="bar"></foo></rpc-reply>`,
},
}
for _, test := range tests {
actual, err := xml.Marshal(test.msg)
fc.AssertEqual(t, nil, err)
fc.AssertEqual(t, test.expected, string(actual))
}
}