-
Notifications
You must be signed in to change notification settings - Fork 115
/
trace_test.go
36 lines (33 loc) · 930 Bytes
/
trace_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
package gout
import (
"bytes"
"testing"
"github.com/guonaihong/gout/dataflow"
"github.com/guonaihong/gout/debug"
)
// 测试trace的入口函数
func Test_Trace(t *testing.T) {
t.Run("TraceJSONToWriter", func(t *testing.T) {
//大约是这样的字符串
//{"DnsDuration":0,"ConnDuration":1490250,"TLSDuration":0,"RequestDuration":33166,"WaitResponeDuration":258084,"ResponseDuration":10708,"TotalDuration":1810834}
ts := createMethodEcho()
defer ts.Close()
var buf bytes.Buffer
err := dataflow.New().GET(ts.URL).Debug(debug.TraceJSONToWriter(&buf)).Do()
if err != nil {
t.Fatal(err)
}
pos := bytes.Index(buf.Bytes(), []byte("ConnDuration"))
if pos == -1 {
t.Fatal("not found ConnDuration")
}
})
t.Run("TraceJSON", func(t *testing.T) {
ts := createMethodEcho()
defer ts.Close()
err := dataflow.New().GET(ts.URL).Debug(debug.TraceJSON()).Do()
if err != nil {
t.Fatal(err)
}
})
}