forked from shiyanhui/dht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blacklist_test.go
57 lines (50 loc) · 853 Bytes
/
blacklist_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
package dht
import (
"fmt"
"testing"
)
var blacklist = newBlackList(256)
func TestGenKey(t *testing.T) {
cases := []struct {
in struct {
ip string
port int
}
out string
}{
{struct {
ip string
port int
}{"0.0.0.0", -1}, "0.0.0.0"},
{struct {
ip string
port int
}{"1.1.1.1", 8080}, "1.1.1.1:8080"},
}
for _, c := range cases {
if blacklist.genKey(c.in.ip, c.in.port) != c.out {
t.Fail()
}
}
}
func TestBlackList(t *testing.T) {
address := []struct {
ip string
port int
}{
{"0.0.0.0", -1},
{"1.1.1.1", 8080},
{"2.2.2.2", 8081},
}
for _, addr := range address {
blacklist.insert(addr.ip, addr.port)
if !blacklist.in(addr.ip, addr.port) {
t.Fail()
}
blacklist.delete(addr.ip, addr.port)
if blacklist.in(addr.ip, addr.port) {
fmt.Println(addr.ip)
t.Fail()
}
}
}