forked from go-pay/gopay
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gopay_test.go
63 lines (56 loc) · 1.67 KB
/
gopay_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
package gopay
import (
"encoding/xml"
"testing"
"time"
"github.com/iGoogle-ink/gotil/xhttp"
"github.com/iGoogle-ink/gotil/xlog"
)
func TestBodyMap_CheckParamsNull(t *testing.T) {
bm := make(BodyMap)
bm.Set("name", "jerry")
bm.Set("age", 2)
bm.Set("phone", "")
bm.Set("pi", 3.1415926)
err := bm.CheckEmptyError("name", "age", "phone")
if err != nil {
xlog.Errorf("bm.CheckEmptyError():error:%+v", err)
return
}
}
func TestNewClient(t *testing.T) {
client := xhttp.NewClient()
res, _, errs := client.Get("http://www.baidu.com").SetTimeout(30 * time.Second).EndBytes()
if len(errs) > 0 {
xlog.Error(errs[0])
return
}
xlog.Info("bs:", res.StatusCode)
}
func TestBodyMap_UnmarshalXML(t *testing.T) {
xmlData := `<xml>
<appid><![CDATA[wx2421b1c4370ec43b]]></appid>
<mch_id><![CDATA[10000100]]></mch_id>
<nonce_str><![CDATA[TeqClE3i0mvn3DrK]]></nonce_str>
<out_refund_no_0><![CDATA[1415701182]]></out_refund_no_0>
<out_trade_no><![CDATA[1415757673]]></out_trade_no>
<refund_count>1</refund_count>
<refund_fee_0>1</refund_fee_0>
<refund_id_0><![CDATA[2008450740201411110000174436]]></refund_id_0>
<refund_status_0><![CDATA[PROCESSING]]></refund_status_0>
<result_code><![CDATA[SUCCESS]]></result_code>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
<sign><![CDATA[1F2841558E233C33ABA71A961D27561C]]></sign>
<transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>
</xml>`
mm := make(BodyMap)
err := xml.Unmarshal([]byte(xmlData), &mm)
if err != nil {
xlog.Errorf("xml.Unmarshal(%s),error:%+v", xmlData, err)
return
}
for k, v := range mm {
xlog.Infof("%s:%s\n", k, v)
}
}