-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve_test.go
84 lines (73 loc) · 1.72 KB
/
serve_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
84
package web1
import (
"fmt"
"testing"
"time"
proto3 "web/proto"
)
var ws = Service()
func init() {
ws.NoHeader = true
}
func TestServe(t *testing.T) {
ws.Timeout = time.Second * 60
ws.Request = func(request proto3.Request) *proto3.Request {
query := QueryForm(request.Path)
fmt.Println(query.Path, query.Get["cid"], string(request.Body))
//构造返回数据
request.HttpStatusCode = "200"
request.ContentType = "text/html"
request.Body = []byte("hello world")
request.Header = nil
//异步返回
ws.Response(request)
//返回有内容直接Response
return nil //&request
}
ws.StartRun("80")
}
func TestQueryForm(t *testing.T) {
var request = proto3.Request{}
request.Path = "/a/b/c/d/search.ashx?cid=888&b=wudongwen&host=r-=com&instanceId=r-uf6m0t1gzn04hfw7q3®ionId=cn"
q := QueryForm(request.Path)
fmt.Println(q)
}
func BenchmarkQueryForm(b *testing.B) {
for i := 0; i < b.N; i++ {
q := QueryForm("/search.ashx?cid=888&b=wudongwen&host=r-=com&instanceId=r-uf6m0t1gzn04hfw7q3®ionId=cn")
if q == nil {
fmt.Println(q)
}
}
}
var body = []byte(`POST /api.ashx HTTP/1.1
Content-Type: application/json
Accept-Encoding: gzip
User-Agent: PostmanRuntime/7.29.0
Accept: */*
Postman-Token: 885a410f-f326-4326-958c-fa4cf2e99333
Host: 127.0.0.1:8086
Connection: keep-alive
Content-Length: 217
{
"cid": "AIRPAZ",
"tripType": "2",
"fromCity": "HKG",
"toCity": "LAX",
"fromDate": "20220728",
"retDate": "20220810",
"adultNumber": 1,
"childNumber": 0,
"channel": "F"
}`)
func TestRequest(t *testing.T) {
req := ws.httpRequest(body)
fmt.Println(req)
}
func BenchmarkRequest(b *testing.B) {
for i := 0; i < b.N; i++ {
req := ws.httpRequest(body)
if req.Message == "" {
}
}
}