forked from kolo/xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
response_test.go
83 lines (72 loc) · 1.67 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
80
81
82
83
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>
<string>410</string>
</value>
</member>
</struct>
</value>
</fault>
</methodResponse>`
func Test_failedResponse(t *testing.T) {
resp := NewResponse([]byte(faultRespXml), 400)
if !resp.Failed() {
t.Fatal("Failed() error: expected true, got false")
}
if resp.Err() == nil {
t.Fatal("Err() error: expected error, got nil")
}
err := resp.Err().(*XmlRpcError)
if err.Code != "410" && err.Err != "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 := NewResponse([]byte(emptyValResp), 201)
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)
}
}