Skip to content

Commit

Permalink
Added a test for multiple IPs per host
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Jun 3, 2021
1 parent 431a74f commit 59ecbb2
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions dnsengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/urlfilter/filterlist"
"github.com/AdguardTeam/urlfilter/filterutil"
Expand Down Expand Up @@ -200,6 +202,17 @@ func TestRegexp(t *testing.T) {
assert.True(t, ok && res.NetworkRule.Text() == text && res.NetworkRule.Whitelist)
}

func TestMultipleIPPerHost(t *testing.T) {
text := `1.1.1.1 example.org
2.2.2.2 example.org`
ruleStorage := newTestRuleStorage(t, 1, text)
dnsEngine := NewDNSEngine(ruleStorage)

res, ok := dnsEngine.Match("example.org")
require.True(t, ok)
require.Equal(t, 2, len(res.HostRulesV4))
}

func TestClientTags(t *testing.T) {
rulesText := `||host1^$ctag=pc|printer
||host1^
Expand Down Expand Up @@ -279,14 +292,6 @@ func TestClientTags(t *testing.T) {
assert.False(t, ok)
}

func assertMatchRuleText(t *testing.T, rulesText string, rules DNSResult, ok bool) {
assert.True(t, ok)
if ok {
assert.NotNil(t, rules.NetworkRule)
assert.Equal(t, rulesText, rules.NetworkRule.Text())
}
}

func TestClient(t *testing.T) {
rulesText := []string{
"||host0^$client=127.0.0.1",
Expand Down Expand Up @@ -533,3 +538,11 @@ func TestDNSEngine_MatchRequest_dnsType(t *testing.T) {
assert.NotContains(t, res.NetworkRule.Text(), "dnstype=")
})
}

func assertMatchRuleText(t *testing.T, rulesText string, rules DNSResult, ok bool) {
assert.True(t, ok)
if ok {
assert.NotNil(t, rules.NetworkRule)
assert.Equal(t, rulesText, rules.NetworkRule.Text())
}
}

0 comments on commit 59ecbb2

Please sign in to comment.