Skip to content

Commit

Permalink
all: improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Dec 18, 2020
1 parent f863a56 commit 44ef59e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion dnsrewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func TestDNSResult_DNSRewrites(t *testing.T) {
|disable_one^$dnsrewrite=127.0.0.2
@@||disable_one^$dnsrewrite=127.0.0.1
|simple_exc^$dnsrewrite=127.0.0.1
@@||simple_exc^
|disable_cname^$dnsrewrite=127.0.0.1
|disable_cname^$dnsrewrite=new_cname
@@||disable_cname^$dnsrewrite=new_cname
Expand All @@ -27,7 +30,7 @@ func TestDNSResult_DNSRewrites(t *testing.T) {
|disable_all^$dnsrewrite=127.0.0.1
|disable_all^$dnsrewrite=127.0.0.2
@@||disable_all^$dnsrewrite=
@@||disable_all^$dnsrewrite
|disable_all_order^$dnsrewrite=127.0.0.1
@@||disable_all_order^$dnsrewrite=
Expand All @@ -54,6 +57,23 @@ func TestDNSResult_DNSRewrites(t *testing.T) {
}
})

t.Run("simple_exc", func(t *testing.T) {
res, ok := dnsEngine.Match(path.Base(t.Name()))

// Simple matching.
assert.True(t, ok)
assert.True(t, res.NetworkRule.Whitelist)

// DNS rewrite matching.
dnsr := res.DNSRewrites()
if assert.Len(t, dnsr, 1) {
dr := dnsr[0].DNSRewrite
assert.Equal(t, dns.RcodeSuccess, dr.RCode)
assert.Equal(t, dns.TypeA, dr.RRType)
assert.Equal(t, ipv4p1, dr.Value)
}
})

t.Run("disable_cname", func(t *testing.T) {
res, ok := dnsEngine.Match(path.Base(t.Name()))
assert.False(t, ok)
Expand Down

0 comments on commit 44ef59e

Please sign in to comment.