forked from kolo/xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
79 lines (69 loc) · 1.57 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package xmlrpc
import (
"testing"
)
const faultRespXml = `
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultString</name>
<value>
<string>You must log in before using this part of Bugzilla.</string>
</value>
</member>
<member>
<name>faultCode</name>
<value>
<int>410</int>
</value>
</member>
</struct>
</value>
</fault>
</methodResponse>`
func Test_failedResponse(t *testing.T) {
resp := Response([]byte(faultRespXml))
if resp.Err() == nil {
t.Fatal("Err() error: expected error, got nil")
}
fault := resp.Err().(FaultError)
if fault.Code != 410 && fault.String != "You must log in before using this part of Bugzilla." {
t.Fatal("Err() error: got wrong error")
}
}
const emptyValResp = `
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>user</name>
<value><string>Joe Smith</string></value>
</member>
<member>
<name>token</name>
<value/>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>`
func Test_responseWithEmptyValue(t *testing.T) {
resp := Response([]byte(emptyValResp))
result := struct {
User string `xmlrpc:"user"`
Token string `xmlrpc:"token"`
}{}
if err := resp.Unmarshal(&result); err != nil {
t.Fatalf("unmarshal error: %v", err)
}
if result.User != "Joe Smith" || result.Token != "" {
t.Fatalf("unexpected result: %v", result)
}
}