-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_test.go
51 lines (43 loc) · 889 Bytes
/
list_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
package block
import (
"os"
"strings"
"testing"
)
func TestListParse(t *testing.T) {
var list = `
# 127.0.0.1 example.com
127.0.0.1 example.org third
008.free-counter.co.uk
com
`
b := new(Block)
os.Remove("/tmp/list_test.db")
b.setupDB("/tmp/list_test.db")
r := strings.NewReader(list)
l := make(map[string]DomainValue)
listRead(r, l, -1)
b.update = l
err := b.UpdateDomains(b.update)
if err != nil {
log.Fatal("failed to update list_test -- ", err)
}
tests := []struct {
name string
blocked bool
}{
{"example.org.", false},
{"example.com.", true},
{"com.", true},
}
for _, test := range tests {
retIP := ""
retCNAME := ""
hasPermit := false
categories := []string{}
got := b.blocked("1.2.3.4", test.name, &retIP, &retCNAME, &hasPermit, &categories)
if got != test.blocked {
t.Errorf("Expected %s to be blocked", test.name)
}
}
}