-
Notifications
You must be signed in to change notification settings - Fork 21
/
engine_test.go
44 lines (34 loc) · 1.04 KB
/
engine_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
package urlfilter
import (
"testing"
"github.com/AdguardTeam/urlfilter/filterlist"
"github.com/AdguardTeam/urlfilter/rules"
"github.com/stretchr/testify/assert"
)
func TestEngineMatchRequest(t *testing.T) {
rulesText := `||example.org^$third-party`
engine := buildEngine(t, rulesText)
request := rules.NewRequest("https://example.org", "", rules.TypeDocument)
result := engine.MatchRequest(request)
assert.Nil(t, result.BasicRule)
assert.Nil(t, result.DocumentRule)
assert.Nil(t, result.ReplaceRules)
assert.Nil(t, result.CspRules)
assert.Nil(t, result.CookieRules)
assert.Nil(t, result.StealthRule)
}
// buildEngine builds filtering engine from the specified set of rules
func buildEngine(t *testing.T, rulesText string) *Engine {
lists := []filterlist.RuleList{
&filterlist.StringRuleList{
ID: 1,
RulesText: rulesText,
IgnoreCosmetic: false,
},
}
ruleStorage, err := filterlist.NewRuleStorage(lists)
if err != nil {
t.Fatalf("failed to create a rule storage: %s", err)
}
return NewEngine(ruleStorage)
}