forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagnostics_test.go
116 lines (108 loc) · 2.86 KB
/
diagnostics_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package cloudflare
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDiagnosticsPerformTraceroute(t *testing.T) {
setup()
defer teardown()
handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, r.Method, "POST", "Expected method 'POST', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"target": "1.1.1.1",
"colos": [
{
"error": "",
"colo": {
"name": "den01",
"city": "Denver, CO, US"
},
"traceroute_time_ms": 969,
"target_summary": {
"asn": "",
"ip": "1.1.1.1",
"name": "1.1.1.1",
"packet_count": 3,
"mean_rtt_ms": 0.021,
"std_dev_rtt_ms": 0.011269427669584647,
"min_rtt_ms": 0.014,
"max_rtt_ms": 0.034
},
"hops": [
{
"packets_ttl": 1,
"packets_sent": 3,
"packets_lost": 0,
"nodes": [
{
"asn": "AS13335",
"ip": "1.1.1.1",
"name": "one.one.one.one",
"packet_count": 3,
"mean_rtt_ms": 0.021,
"std_dev_rtt_ms": 0.011269427669584647,
"min_rtt_ms": 0.014,
"max_rtt_ms": 0.034
}
]
}
]
}
]
}
]
}
`)
}
mux.HandleFunc("/accounts/01a7362d577a6c3019a474fd6f485823/diagnostics/traceroute", handler)
want := []DiagnosticsTracerouteResponseResult{{
Target: "1.1.1.1",
Colos: []DiagnosticsTracerouteResponseColos{{
Error: "",
Colo: DiagnosticsTracerouteResponseColo{
Name: "den01", City: "Denver, CO, US",
},
TracerouteTimeMs: 969,
TargetSummary: DiagnosticsTracerouteResponseNodes{
Asn: "",
IP: "1.1.1.1",
Name: "1.1.1.1",
PacketCount: 3,
MeanRttMs: 0.021,
StdDevRttMs: 0.011269427669584647,
MinRttMs: 0.014,
MaxRttMs: 0.034,
},
Hops: []DiagnosticsTracerouteResponseHops{{
PacketsTTL: 1,
PacketsSent: 3,
PacketsLost: 0,
Nodes: []DiagnosticsTracerouteResponseNodes{{
Asn: "AS13335",
IP: "1.1.1.1",
Name: "one.one.one.one",
PacketCount: 3,
MeanRttMs: 0.021,
StdDevRttMs: 0.011269427669584647,
MinRttMs: 0.014,
MaxRttMs: 0.034,
}},
}},
}},
},
}
opts := DiagnosticsTracerouteConfigurationOptions{PacketsPerTTL: 1, PacketType: "imcp", MaxTTL: 1, WaitTime: 1}
trace, err := client.PerformTraceroute("01a7362d577a6c3019a474fd6f485823", []string{"1.1.1.1"}, []string{"den01"}, opts)
if assert.NoError(t, err) {
assert.Equal(t, want, trace)
}
}