-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace_test.go
84 lines (67 loc) · 1.89 KB
/
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
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 httptrace
import (
"crypto/tls"
"net"
nht "net/http/httptrace"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestConvertTLSVersion(t *testing.T) {
assert := assert.New(t)
assert.Equal("tls1.0", convertTLSVersion(tls.VersionTLS10))
assert.Equal("-", convertTLSVersion(0))
assert.Equal("1", convertTLSVersion(1))
}
func TestConvertCipherSuite(t *testing.T) {
assert := assert.New(t)
assert.Equal("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", convertCipherSuite(tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA))
assert.Equal("-", convertCipherSuite(0))
assert.Equal("1", convertCipherSuite(1))
}
func TestTrace(t *testing.T) {
assert := assert.New(t)
trace, ht := NewClientTrace()
trace.GetConn("1.1.1.1:80")
time.Sleep(time.Millisecond)
trace.DNSStart(nht.DNSStartInfo{
Host: "aslant.site",
})
time.Sleep(time.Millisecond)
addrs := make([]net.IPAddr, 0)
addrs = append(addrs, net.IPAddr{
IP: net.IPv4(1, 1, 1, 1),
})
trace.DNSDone(nht.DNSDoneInfo{
Addrs: addrs,
})
time.Sleep(time.Millisecond)
trace.ConnectStart("tcp", "1.1.1.1")
time.Sleep(time.Millisecond)
trace.WroteHeaders()
trace.WroteRequest(nht.WroteRequestInfo{})
trace.WroteRequest(nht.WroteRequestInfo{})
trace.ConnectDone("", "", nil)
time.Sleep(time.Millisecond)
trace.TLSHandshakeStart()
time.Sleep(time.Millisecond)
trace.TLSHandshakeDone(tls.ConnectionState{}, nil)
time.Sleep(time.Millisecond)
trace.GotConn(nht.GotConnInfo{
Reused: true,
WasIdle: true,
})
time.Sleep(time.Millisecond)
trace.GotFirstResponseByte()
time.Sleep(time.Millisecond)
ht.Finish()
stats := ht.Stats()
assert.NotEqual(0, stats.GetConnection)
assert.NotEqual(0, stats.DNSLookup)
assert.NotEqual(0, stats.TCPConnection)
assert.NotEqual(0, stats.TLSHandshake)
assert.NotEqual(0, stats.ServerProcessing)
assert.NotEqual(0, stats.ContentTransfer)
assert.NotEqual(0, stats.Total)
assert.NotEmpty(stats.String())
}