-
-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathfilter_test.go
More file actions
37 lines (32 loc) · 1.14 KB
/
filter_test.go
File metadata and controls
37 lines (32 loc) · 1.14 KB
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
package goatcounter
import "testing"
func TestFilterMatch(t *testing.T) {
tests := []struct {
query, path, title string
event, want bool
}{
{"", "/hello", "Hello, world", false, true},
{"e", "/hello", "Hello, world", false, true},
{"/h in:path", "/hello", "Hello, world", false, true},
{"/h in:title", "/hello", "Hello, world", false, false},
{", world in:path", "/hello", "Hello, world", false, false},
{", world in:title", "/hello", "Hello, world", false, true},
{"/h in:path at:end", "/hello", "Hello, world", false, false},
{"/h in:path at:start", "/hello", "Hello, world", false, true},
{"/h in:path at:start at:end", "/hello", "Hello, world", false, false},
{"/hello in:path at:start at:end", "/hello", "Hello, world", false, true},
{"HELLO", "/hello", "Hello, world", false, true},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
have := Filter{Query: tt.query}.Match(tt.path, tt.title, tt.event)
if have != tt.want {
t.Error(tt.query)
}
have = Filter{Query: tt.query + " :not"}.Match(tt.path, tt.title, tt.event)
if have == tt.want {
t.Error(":NOT →", tt.query)
}
})
}
}