forked from kolo/xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_test.go
62 lines (51 loc) · 1.48 KB
/
request_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package xmlrpc
import (
"encoding/xml"
"testing"
)
func Test_buildValueElement_EscapesString(t *testing.T) {
escaped := buildValueElement("Johnson & Johnson > 1")
assert_equal(t, "<value><string>Johnson & Johnson > 1</string></value>", escaped)
}
const PARAMS_REQUEST = `
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>method</methodName>
<params>
<param>
<value>
<string>user</string>
</value>
</param>
<param>
<value>
<string>pass</string>
</value>
</param>
</params>
</methodCall>
`
type MethodCall struct {
XMLName xml.Name `xml:"methodCall"`
MethodName string `xml:"methodName"`
Params []ParamsTy `xml:"params>param"`
}
type ParamsTy struct {
Value string `xml:"value>string"`
}
func Test_buildRequestBody(t *testing.T) {
var xml_expected MethodCall
xml.Unmarshal([]byte(PARAMS_REQUEST), &xml_expected)
params := Params{Params: []interface{}{"user", "pass"}}
request := buildRequestBody("method", []interface{}{params})
var xml_request MethodCall
xml.Unmarshal([]byte(request), &xml_request)
assert_equal(t, xml_request.MethodName, xml_expected.MethodName)
assert_equal(t, xml_request.Params[0], xml_expected.Params[0])
assert_equal(t, xml_request.Params[1], xml_expected.Params[1])
}
func Test_buildArrayElement(t *testing.T) {
a := []interface{}{1}
var arrayElement = buildArrayElement(a)
assert_equal(t, arrayElement, "<array><data><value><int>1</int></value></data></array>")
}