Skip to content

Commit

Permalink
dnsforward: imp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Nov 25, 2024
1 parent 1ca3534 commit a5b6c83
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions internal/dnsforward/dnsforward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,8 @@ func TestServerRace(t *testing.T) {
}

func TestSafeSearch(t *testing.T) {
var (
upsCalledCounter uint32
wantCNAMECounter uint32
const (
googleSafeSearch = "forcesafesearch.google.com."
)

safeSearchConf := filtering.SafeSearchConfig{
Expand Down Expand Up @@ -541,21 +540,12 @@ func TestSafeSearch(t *testing.T) {
ServePlainDNS: true,
}
s := createTestServer(t, filterConf, forwardConf)
ups := aghtest.NewUpstreamMock(func(req *dns.Msg) (resp *dns.Msg, err error) {
atomic.AddUint32(&upsCalledCounter, 1)

resp = new(dns.Msg).SetReply(req)
resp.Answer = []dns.RR{&dns.A{
Hdr: dns.RR_Header{
Name: req.Question[0].Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 60,
},
A: []byte{1, 2, 3, 4},
}}
ups := aghtest.NewUpstreamMock(func(req *dns.Msg) (resp *dns.Msg, err error) {
pt := testutil.PanicT{}
assert.Equal(pt, googleSafeSearch, req.Question[0].Name)

return resp, nil
return aghtest.MatchedResponse(req, dns.TypeA, googleSafeSearch, "1.2.3.4"), nil
})
s.conf.UpstreamConfig.Upstreams = []upstream.Upstream{ups}

Expand Down Expand Up @@ -618,8 +608,6 @@ func TestSafeSearch(t *testing.T) {

a := testutil.RequireTypeAssert[*dns.A](t, reply.Answer[1])
assert.NotEmpty(t, a.A)

atomic.AddUint32(&wantCNAMECounter, 1)
} else {
require.Len(t, reply.Answer, 1)

Expand All @@ -628,13 +616,6 @@ func TestSafeSearch(t *testing.T) {
}
})
}

t.Run("mock_upstream_is_used", func(t *testing.T) {
called := atomic.LoadUint32(&upsCalledCounter)
want := atomic.LoadUint32(&wantCNAMECounter)

assert.Equal(t, want, called)
})
}

func TestInvalidRequest(t *testing.T) {
Expand Down

0 comments on commit a5b6c83

Please sign in to comment.