-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
refspam_test.go
51 lines (42 loc) · 1.01 KB
/
refspam_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
// Copyright © Martin Tournoij – This file is part of GoatCounter and published
// under the terms of a slightly modified EUPL v1.2 license, which can be found
// in the LICENSE file or at https://license.goatcounter.com
package goatcounter
import (
"testing"
)
func TestRefspam(t *testing.T) {
tests := []struct {
in string
want bool
}{
{"notinthelist.com", false},
{"foo.notinthelist.com", false},
{"localhost", true},
{"a.localhost", true},
{"c.a.localhost", true},
{"adcash.com", true},
{"d.adcash.com", true},
{"dadcash.com", false},
{"localhost.com", false},
{"asdlocalhost.com", false},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
got := isRefspam(tt.in)
if got != tt.want {
t.Errorf("\ngot: %t\nwant: %t", got, tt.want)
}
})
}
}
func BenchmarkRefspam(b *testing.B) {
isRefspam("notinthelist.com") // Run the sync.Once
b.ReportAllocs()
b.ResetTimer()
v := false
for n := 0; n < b.N; n++ {
v = isRefspam("notinthelist.com")
}
_ = v
}