-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilsHostString_test.go
151 lines (142 loc) · 4.13 KB
/
utilsHostString_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
141
142
143
144
145
146
147
148
149
150
151
package pighosts
import (
"reflect"
"runtime"
"strings"
"testing"
)
func init() {
InitPigHosts(true)
ReadFileConf()
}
func Test_removeComments(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want string
}{
{"remove: comment_1", args{s: "host.local.it #test"}, "host.local.it"},
{"remove: comment_2", args{s: "host.local.it#test"}, "host.local.it"},
{"remove: comment_3", args{s: "#host.local.it"}, ""},
{"remove: comment_4", args{s: "# host.local.it #test"}, ""},
{"remove: comment_space", args{s: "255.255.255.255 broadcasthost"}, "255.255.255.255 broadcasthost"},
{"remove: comment_tab", args{s: "255.255.255.255 broadcasthost"}, "255.255.255.255 broadcasthost"},
{"remove: comment_tab_upper", args{s: "255.255.255.255 BROADCASTHOST"}, "255.255.255.255 broadcasthost"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := removeComments(tt.args.s); got != tt.want {
t.Errorf("removeComments() = %v, want %v", got, tt.want)
}
})
}
}
func Test_removeLocalHost(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want string
}{
{"remove: 127.0.0.1", args{s: "127.0.0.1 host.local.it"}, "host.local.it"},
{"remove: 127.0.0.1 with spaces", args{s: "127.0.0.1 host.local.it "}, "host.local.it"},
{"remove: 0.0.0.0", args{s: "0.0.0.0 host.local.it"}, "host.local.it"},
{"remove: 0.0.0.0 with spaces", args{s: "0.0.0.0 host.local.it"}, "host.local.it"},
{"remove: 0.0.0.0 with spaces 2", args{s: " 0.0.0.0 host.local.it "}, "host.local.it"},
{"remove: 0.0.0.0 with localhost", args{s: "localhost"}, ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := removeLocalHost(tt.args.s); got != tt.want {
t.Errorf("removeLocalHost() = %v, want %v", got, tt.want)
}
})
}
}
func Test_prepareHostsList(t *testing.T) {
tmpUrls := make([]string, 0)
tmpUrl, _ := downlaodRemoteList("https://drive.google.com/uc?authuser=0&id=1-QRZf_ymrWFZ4XgmXTZJrkhqzhdJMphB&export=download")
tmpUrls = append(tmpUrls, tmpUrl...)
tmpUrl, _ = downlaodRemoteList("https://drive.google.com/uc?authuser=0&id=1BfGJJLtimhoOi9Sm3jYLF6d8XtYBJ5KY&export=download")
tmpUrls = append(tmpUrls, tmpUrl...)
type args struct {
urls []string
}
tests := []struct {
name string
args args
want map[string]int
wantErr bool
}{
{"Test_prepareHostsList_1",
args{urls: tmpUrls},
map[string]int{
"123date.me": 1,
"12place.com": 1,
"165a7.v.fwmrm.net": 1,
"180searchassistant.com": 1,
"188server.com": 1,
"1ccbt.com": 1,
"1empiredirect.com": 2,
"1phads.com": 2,
"test.test.io": 1},
false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := prepareHostsList(tt.args.urls)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("prepareHostsList() = %v, want %v", got, tt.want)
}
})
}
}
func Test_splitHostPerLine(t *testing.T) {
type args struct {
hosts map[string]int
}
result := []int{10, 7}
if runtime.GOOS != "windows" {
result = []int{2, 2}
}
tests := []struct {
name string
args args
want []int
}{
{"Test_splitHostPerLine_1",
args{hosts: map[string]int{
"123date.me": 1,
"12place.com": 1,
"165a7.v.fwmrm.net": 1,
"180searchassistant.com": 1,
"188server.com": 1,
"1ccbt.com": 1,
"1empiredirect.com": 2,
"1phads.com": 2,
"1phads2.com": 2,
"1phads3.com": 2,
"1phads4.com": 2,
"1phads5.com": 2,
"1phads6.com": 2,
"1phads7.com": 2,
"test.test.io": 1},
},
result,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := splitHostPerLine(tt.args.hosts)
iGot := []int{len(strings.Split(got[0], " ")), len(strings.Split(got[1], " "))}
if !reflect.DeepEqual(iGot, tt.want) {
t.Errorf("splitHostPerLine() = %v, want %v", iGot, tt.want)
}
})
}
}