-
Notifications
You must be signed in to change notification settings - Fork 2
/
cf-speedtester_test.go
140 lines (127 loc) · 3.13 KB
/
cf-speedtester_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package cf_speedtester
import (
"fmt"
"github.com/fireinrain/cf-speedtester/config"
"github.com/fireinrain/cf-speedtester/handler"
"net"
"testing"
"time"
)
func TestCFSpeedTester_DoSpeedTest(t *testing.T) {
client := NewCFSpeedTestClient(
config.WithMaxDelay(300*time.Millisecond),
config.WithMinSpeed(2),
config.WithTestCount(5),
)
client.DoSpeedTest()
results := client.SpeedResults
fmt.Println(results)
client.ExportToCSV("results.csv")
}
func TestCFSpeedTester_DoSpeedTestForResult(t *testing.T) {
client := NewCFSpeedTestClient(
config.WithMaxDelay(300*time.Millisecond),
config.WithMinSpeed(2),
config.WithTestCount(5),
)
result := client.DoSpeedTestForResult()
fmt.Println(result)
}
func TestForCustomDownloadUrl(t *testing.T) {
client := NewCFSpeedTestClient(
config.WithMaxDelay(300*time.Millisecond),
config.WithMinSpeed(2),
config.WithTestCount(5),
config.WithDownloadUrl("https://youself-download-url.com"),
)
result := client.DoSpeedTestForResult()
fmt.Println(result)
}
func TestNewCFSpeedTestClient(t *testing.T) {
var ips = []string{
"193.122.125.193",
"193.122.119.93",
"193.122.119.34",
"193.122.108.223",
"193.122.114.201",
"193.122.114.63",
"193.122.121.37",
"193.122.113.19",
"193.122.112.125",
"193.122.116.161",
}
var ipList []*net.IPAddr
for _, ip := range ips {
addr := handler.IPStrToIPAddr(ip)
ipList = append(ipList, addr)
}
client := NewCFSpeedTestClient(
config.WithMinDelay(300*time.Millisecond),
config.WithMinSpeed(2),
config.WithTestCount(10),
config.WithIPListForTest(ipList),
)
result := client.DoSpeedTestForResult()
fmt.Println(result)
}
func TestIPBanedInChina(t *testing.T) {
var ips = []string{
"193.122.125.193",
"193.122.119.93",
"193.122.119.34",
"193.122.108.223",
"193.122.114.201",
"193.122.114.63",
"193.122.121.37",
"193.122.113.19",
}
var ipList []*net.IPAddr
for _, ip := range ips {
addr := handler.IPStrToIPAddr(ip)
ipList = append(ipList, addr)
}
client := NewCFSpeedTestClient(
config.WithMaxDelay(300*time.Millisecond),
config.WithMinSpeed(2),
config.WithTestCount(1),
config.WithIPListForTest(ipList),
config.WithEnableIPBanCheck(true),
config.WithIPBanChecker(YouselfIPBanChecker),
)
result := client.DoSpeedTestForResult()
fmt.Println(result)
}
func YouselfIPBanChecker(some any) any {
//do you check logic
return some
}
func TestWithISOIP(t *testing.T) {
var ips = []string{
"193.122.125.193",
"193.122.119.93",
"193.122.119.34",
"193.122.108.223",
"193.122.114.201",
"193.122.114.63",
"193.122.121.37",
"193.122.113.19",
"146.70.175.116",
}
var ipList []*net.IPAddr
for _, ip := range ips {
addr := handler.IPStrToIPAddr(ip)
ipList = append(ipList, addr)
}
client := NewCFSpeedTestClient(
config.WithMaxDelay(300*time.Millisecond),
config.WithMinSpeed(2),
config.WithTestCount(1),
config.WithIPListForTest(ipList),
// i want to get the cdn ip belongs to NL(Netherlands ISO code)
config.WithWantedISOIP([]string{"NL"}),
config.WithEnableIPBanCheck(true),
config.WithIPBanChecker(YouselfIPBanChecker),
)
result := client.DoSpeedTestForResult()
fmt.Println(result)
}