-
Notifications
You must be signed in to change notification settings - Fork 1
/
tor_test.go
58 lines (48 loc) · 1.23 KB
/
tor_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
package main
import (
"testing"
)
var torTest = TorStruct{
TorList: nil,
Port: "2525",
IPAddr: "127.0.0.1",
Country: "ID",
City: "Jakarta",
Load: 100,
}
func TestChangeCountry(t *testing.T) {
countryTest := "JP"
t.Logf("new country %s", countryTest)
torTest.AddCountry(countryTest)
if torTest.Country != countryTest {
t.Errorf("country should be changed into %s", countryTest)
}
}
func TestChangeIP(t *testing.T) {
ipTest := "192.168.1.254"
t.Logf("new ip %s", ipTest)
torTest.AddIP(ipTest)
if torTest.IPAddr != ipTest {
t.Errorf("ip should be changed into %s", ipTest)
}
}
func TestTorRRLB(t *testing.T) {
torTestSlice := []TorStruct{torTest, torTest}
t.Logf("test round robin LB")
torTestLb := GetTorLB(torTestSlice)
//it's should be the first slice of torTestSlice
if torTestLb.Load != torTest.Load+1 {
t.Errorf("failed to counter TorStruct load")
}
}
func TestTorLcLB(t *testing.T) {
newTorTest := torTest
newTorTest.Load = 10
t.Logf("test least connetion LB")
torTestSlice := []TorStruct{torTest, newTorTest}
torTestLb := GetTorLBWeight(torTestSlice)
//it's should be the secound slice of torTestSlice
if torTestLb.Load != newTorTest.Load+1 {
t.Errorf("failed to counter TorStruct load")
}
}