dnsforward: imp tests

This commit is contained in:
Stanislav Chzhen 2024-11-22 19:54:53 +03:00
parent efabbe318e
commit 82851aa825
1 changed files with 8 additions and 1 deletions

View File

@ -500,6 +500,8 @@ func TestServerRace(t *testing.T) {
} }
func TestSafeSearch(t *testing.T) { func TestSafeSearch(t *testing.T) {
var upsCalledCounter uint32
safeSearchConf := filtering.SafeSearchConfig{ safeSearchConf := filtering.SafeSearchConfig{
Enabled: true, Enabled: true,
Google: true, Google: true,
@ -537,6 +539,8 @@ func TestSafeSearch(t *testing.T) {
} }
s := createTestServer(t, filterConf, forwardConf) s := createTestServer(t, filterConf, forwardConf)
ups := aghtest.NewUpstreamMock(func(req *dns.Msg) (resp *dns.Msg, err error) { ups := aghtest.NewUpstreamMock(func(req *dns.Msg) (resp *dns.Msg, err error) {
atomic.AddUint32(&upsCalledCounter, 1)
resp = new(dns.Msg).SetReply(req) resp = new(dns.Msg).SetReply(req)
resp.Answer = []dns.RR{&dns.A{ resp.Answer = []dns.RR{&dns.A{
Hdr: dns.RR_Header{ Hdr: dns.RR_Header{
@ -599,7 +603,6 @@ func TestSafeSearch(t *testing.T) {
t.Run(tc.host, func(t *testing.T) { t.Run(tc.host, func(t *testing.T) {
req := createTestMessage(tc.host) req := createTestMessage(tc.host)
// TODO(a.garipov): Create our own helper for this.
var reply *dns.Msg var reply *dns.Msg
reply, err = dns.Exchange(req, addr) reply, err = dns.Exchange(req, addr)
require.NoError(t, err) require.NoError(t, err)
@ -620,6 +623,10 @@ func TestSafeSearch(t *testing.T) {
} }
}) })
} }
t.Run("mock_upstream_is_used", func(t *testing.T) {
assert.Positive(t, atomic.LoadUint32(&upsCalledCounter))
})
} }
func TestInvalidRequest(t *testing.T) { func TestInvalidRequest(t *testing.T) {