-
Notifications
You must be signed in to change notification settings - Fork 9
/
blacklist_test.go
51 lines (44 loc) · 1.29 KB
/
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
package main
import (
"sort"
"testing"
)
var (
testBlacklistPath = "./data/test-blacklist.txt"
)
func TestBlacklist_Size(t *testing.T) {
expectedSize := 3
blacklist := LoadBlacklistOrFail(testBlacklistPath)
size := blacklist.Size()
if size != expectedSize {
t.Errorf("Size was incorrect, got: %d, expected: %d", size, expectedSize)
}
}
func TestBlacklist_Contains_Present(t *testing.T) {
domain := "a.example.com"
blacklist := LoadBlacklistOrFail(testBlacklistPath)
if !blacklist.Contains(domain) {
t.Errorf("Blacklist should contain %s, but it was absent", domain)
}
}
func TestBlacklist_Contains_Absent(t *testing.T) {
domain := "absent.example.com"
blacklist := LoadBlacklistOrFail(testBlacklistPath)
if blacklist.Contains(domain) {
t.Errorf("Blacklist should not contain %s, but it was present", domain)
}
}
func TestBlacklist_Contains_UpperCase(t *testing.T) {
domain := "A.example.COM"
blacklist := LoadBlacklistOrFail(testBlacklistPath)
if !blacklist.Contains(domain) {
t.Errorf("Blacklist should contain %s, but it was absent", domain)
}
}
func TestBlacklist_FileSorted(t *testing.T) {
blacklist := LoadBlacklistOrFail(blacklistPath)
sorted := sort.StringsAreSorted(blacklist.array)
if !sorted {
t.Errorf("The blacklist file at path %s must be sorted", blacklistPath)
}
}