-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhttp_client_test.go
54 lines (47 loc) · 1.22 KB
/
http_client_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
// Copyright 2021 YBCZ, Inc. All rights reserved.
//
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file in the root of the source
// tree.
package wx
import (
"bytes"
"encoding/json"
"github.com/blusewang/wx/mch_api"
"io/ioutil"
"log"
"net/http"
"testing"
"time"
)
func TestMt_RoundTrip(t *testing.T) {
log.SetFlags(log.Ltime | log.Lshortfile)
RegisterHook(func(req *http.Request, reqBody []byte, res *http.Response, startAt time.Time, stopAt time.Time, err error) {
var data struct {
Method string `json:"method"`
Url string `json:"url"`
Body string `json:"body"`
ResBody string `json:"res_body"`
}
data.Method = req.Method
data.Url = req.URL.String()
data.Body = string(reqBody)
if res.Body != nil {
raw, _ := ioutil.ReadAll(res.Body)
data.ResBody = string(raw)
res.Body = ioutil.NopCloser(bytes.NewReader(raw))
}
raw, err := json.Marshal(data)
log.Println(string(raw), err)
})
var mch = MchAccount{
MchId: "",
MchKeyV2: "",
MchKeyV3: "",
}
mch.NewMchReq(mch_api.PayOrderQuery)
}
func TestRegisterHook(t *testing.T) {
log.SetFlags(log.Ltime | log.Lshortfile)
log.Println(client().Get("https://httpbin.org/delay/6"))
}