@@ -11,7 +11,6 @@ import (
1111
1212 "github.com/AdguardTeam/dnsproxy/internal/dnsproxytest"
1313 "github.com/AdguardTeam/dnsproxy/upstream"
14- "github.com/AdguardTeam/golibs/logutil/slogutil"
1514 "github.com/AdguardTeam/golibs/netutil"
1615 "github.com/AdguardTeam/golibs/testutil"
1716 "github.com/AdguardTeam/golibs/testutil/servicetest"
@@ -53,14 +52,12 @@ func newTestCache(tb testing.TB, conf *cacheConfig) (c *cache) {
5352
5453func TestServeCached (t * testing.T ) {
5554 dnsProxy := mustNew (t , & Config {
56- Logger : slogutil .NewDiscardLogger (),
57- UDPListenAddr : []* net.UDPAddr {net .UDPAddrFromAddrPort (localhostAnyPort )},
58- TCPListenAddr : []* net.TCPAddr {net .TCPAddrFromAddrPort (localhostAnyPort )},
59- UpstreamConfig : newTestUpstreamConfig (t , defaultTimeout , testDefaultUpstreamAddr ),
60- TrustedProxies : defaultTrustedProxies ,
61- RatelimitSubnetLenIPv4 : 24 ,
62- RatelimitSubnetLenIPv6 : 64 ,
63- CacheEnabled : true ,
55+ Logger : testLogger ,
56+ UDPListenAddr : []* net.UDPAddr {net .UDPAddrFromAddrPort (localhostAnyPort )},
57+ TCPListenAddr : []* net.TCPAddr {net .TCPAddrFromAddrPort (localhostAnyPort )},
58+ UpstreamConfig : newTestUpstreamConfig (t , defaultTimeout , testDefaultUpstreamAddr ),
59+ TrustedProxies : defaultTrustedProxies ,
60+ CacheEnabled : true ,
6461 })
6562
6663 // Start listening.
@@ -75,7 +72,7 @@ func TestServeCached(t *testing.T) {
7572 }).SetQuestion ("google.com." , dns .TypeA )
7673 reply .SetEdns0 (defaultUDPBufSize , false )
7774
78- dnsProxy .cache .set (reply , upstreamWithAddr , slogutil . NewDiscardLogger () )
75+ dnsProxy .cache .set (reply , upstreamWithAddr , testLogger )
7976
8077 // Create a DNS-over-UDP client connection.
8178 addr := dnsProxy .Addr (ProtoUDP )
@@ -199,7 +196,7 @@ func TestCacheDO(t *testing.T) {
199196 reply .SetEdns0 (4096 , true )
200197
201198 // Store in cache.
202- testCache .set (reply , upstreamWithAddr , slogutil . NewDiscardLogger () )
199+ testCache .set (reply , upstreamWithAddr , testLogger )
203200
204201 // Make a request.
205202 request := (& dns.Msg {}).SetQuestion ("google.com." , dns .TypeA )
@@ -230,8 +227,6 @@ func TestCacheDO(t *testing.T) {
230227}
231228
232229func TestCacheCNAME (t * testing.T ) {
233- l := slogutil .NewDiscardLogger ()
234-
235230 testCache := newTestCache (t , nil )
236231
237232 // Fill the cache
@@ -241,7 +236,7 @@ func TestCacheCNAME(t *testing.T) {
241236 },
242237 Answer : []dns.RR {newRR (t , "google.com." , dns .TypeCNAME , 3600 , "test.google.com." )},
243238 }).SetQuestion ("google.com." , dns .TypeA )
244- testCache .set (reply , upstreamWithAddr , l )
239+ testCache .set (reply , upstreamWithAddr , testLogger )
245240
246241 // Create a DNS request.
247242 request := (& dns.Msg {}).SetQuestion ("google.com." , dns .TypeA )
@@ -254,7 +249,7 @@ func TestCacheCNAME(t *testing.T) {
254249
255250 // Now fill the cache with a cacheable CNAME response.
256251 reply .Answer = append (reply .Answer , newRR (t , "google.com." , dns .TypeA , 3600 , net.IP {8 , 8 , 8 , 8 }))
257- testCache .set (reply , upstreamWithAddr , l )
252+ testCache .set (reply , upstreamWithAddr , testLogger )
258253
259254 // We are testing that a proper CNAME response gets cached
260255 t .Run ("cnames_exist" , func (t * testing.T ) {
@@ -277,7 +272,7 @@ func TestCache_uncacheable(t *testing.T) {
277272 reply := (& dns.Msg {}).SetRcode (request , dns .RcodeBadAlg )
278273
279274 // We are testing that SERVFAIL responses aren't cached
280- testCache .set (reply , upstreamWithAddr , slogutil . NewDiscardLogger () )
275+ testCache .set (reply , upstreamWithAddr , testLogger )
281276
282277 r , expired , _ := testCache .get (request )
283278 assert .Nil (t , r )
@@ -318,20 +313,16 @@ func TestCacheExpiration(t *testing.T) {
318313 t .Parallel ()
319314
320315 dnsProxy := mustNew (t , & Config {
321- Logger : slogutil .NewDiscardLogger (),
322- UDPListenAddr : []* net.UDPAddr {net .UDPAddrFromAddrPort (localhostAnyPort )},
323- TCPListenAddr : []* net.TCPAddr {net .TCPAddrFromAddrPort (localhostAnyPort )},
324- UpstreamConfig : newTestUpstreamConfig (t , defaultTimeout , testDefaultUpstreamAddr ),
325- TrustedProxies : defaultTrustedProxies ,
326- RatelimitSubnetLenIPv4 : 24 ,
327- RatelimitSubnetLenIPv6 : 64 ,
328- CacheEnabled : true ,
316+ Logger : testLogger ,
317+ UDPListenAddr : []* net.UDPAddr {net .UDPAddrFromAddrPort (localhostAnyPort )},
318+ TCPListenAddr : []* net.TCPAddr {net .TCPAddrFromAddrPort (localhostAnyPort )},
319+ UpstreamConfig : newTestUpstreamConfig (t , defaultTimeout , testDefaultUpstreamAddr ),
320+ TrustedProxies : defaultTrustedProxies ,
321+ CacheEnabled : true ,
329322 })
330323
331324 servicetest .RequireRun (t , dnsProxy , testTimeout )
332325
333- l := slogutil .NewDiscardLogger ()
334-
335326 // Create dns messages with TTL of 1 second.
336327 rrs := []dns.RR {
337328 newRR (t , "youtube.com." , dns .TypeA , 1 , net.IP {173 , 194 , 221 , 198 }),
@@ -346,7 +337,7 @@ func TestCacheExpiration(t *testing.T) {
346337 },
347338 Answer : []dns.RR {dns .Copy (rr )},
348339 }).SetQuestion (rr .Header ().Name , dns .TypeA )
349- dnsProxy .cache .set (rep , upstreamWithAddr , l )
340+ dnsProxy .cache .set (rep , upstreamWithAddr , testLogger )
350341 replies [i ] = rep
351342 }
352343
@@ -375,18 +366,16 @@ func TestCacheExpirationWithTTLOverride(t *testing.T) {
375366 u := testUpstream {}
376367
377368 dnsProxy := mustNew (t , & Config {
378- Logger : slogutil . NewDiscardLogger () ,
369+ Logger : testLogger ,
379370 UDPListenAddr : []* net.UDPAddr {net .UDPAddrFromAddrPort (localhostAnyPort )},
380371 TCPListenAddr : []* net.TCPAddr {net .TCPAddrFromAddrPort (localhostAnyPort )},
381372 UpstreamConfig : & UpstreamConfig {
382373 Upstreams : []upstream.Upstream {& u },
383374 },
384- TrustedProxies : defaultTrustedProxies ,
385- RatelimitSubnetLenIPv4 : 24 ,
386- RatelimitSubnetLenIPv6 : 64 ,
387- CacheEnabled : true ,
388- CacheMinTTL : 20 ,
389- CacheMaxTTL : 40 ,
375+ TrustedProxies : defaultTrustedProxies ,
376+ CacheEnabled : true ,
377+ CacheMinTTL : 20 ,
378+ CacheMaxTTL : 40 ,
390379 })
391380
392381 servicetest .RequireRun (t , dnsProxy , testTimeout )
@@ -556,8 +545,6 @@ func TestCache(t *testing.T) {
556545}
557546
558547func (tests testCases ) run (t * testing.T ) {
559- l := slogutil .NewDiscardLogger ()
560-
561548 testCache := newTestCache (t , nil )
562549
563550 for _ , res := range tests .cache {
@@ -567,7 +554,7 @@ func (tests testCases) run(t *testing.T) {
567554 },
568555 Answer : res .a ,
569556 }).SetQuestion (res .q , res .t )
570- testCache .set (reply , upstreamWithAddr , l )
557+ testCache .set (reply , upstreamWithAddr , testLogger )
571558 }
572559
573560 for _ , tc := range tests .cases {
@@ -590,7 +577,7 @@ func (tests testCases) run(t *testing.T) {
590577 Answer : tc .a ,
591578 }).SetQuestion (tc .q , tc .t )
592579
593- testCache .set (reply , upstreamWithAddr , l )
580+ testCache .set (reply , upstreamWithAddr , testLogger )
594581
595582 requireEqualMsgs (t , ci .m , reply )
596583 }
@@ -637,7 +624,7 @@ func setAndGetCache(t *testing.T, c *cache, g *sync.WaitGroup, host, ip string)
637624 Answer : []dns.RR {newRR (t , host , dns .TypeA , 1 , ipAddr )},
638625 }).SetQuestion (host , dns .TypeA )
639626
640- c .set (dnsMsg , upstreamWithAddr , slogutil . NewDiscardLogger () )
627+ c .set (dnsMsg , upstreamWithAddr , testLogger )
641628
642629 for range 2 {
643630 ci , expired , key := c .get (dnsMsg )
@@ -663,7 +650,6 @@ func TestCache_getWithSubnet(t *testing.T) {
663650 req := (& dns.Msg {}).SetQuestion (testFQDN , dns .TypeA )
664651 mask16 := net .CIDRMask (16 , netutil .IPv4BitLen )
665652 mask24 := net .CIDRMask (24 , netutil .IPv4BitLen )
666- l := slogutil .NewDiscardLogger ()
667653
668654 c := newTestCache (t , & cacheConfig {withECS : true })
669655
@@ -677,7 +663,7 @@ func TestCache_getWithSubnet(t *testing.T) {
677663 resp := (& dns.Msg {
678664 Answer : []dns.RR {newRR (t , testFQDN , dns .TypeA , 1 , net.IP {1 , 1 , 1 , 1 })},
679665 }).SetReply (req )
680- c .setWithSubnet (resp , upstreamWithAddr , & net.IPNet {IP : ip1234 , Mask : mask16 }, slogutil . NewDiscardLogger () )
666+ c .setWithSubnet (resp , upstreamWithAddr , & net.IPNet {IP : ip1234 , Mask : mask16 }, testLogger )
681667
682668 t .Run ("different_ip" , func (t * testing.T ) {
683669 ci , expired , key := c .getWithSubnet (req , & net.IPNet {IP : ip2234 , Mask : mask24 })
@@ -690,13 +676,13 @@ func TestCache_getWithSubnet(t *testing.T) {
690676 resp = (& dns.Msg {
691677 Answer : []dns.RR {newRR (t , testFQDN , dns .TypeA , 1 , net.IP {2 , 2 , 2 , 2 })},
692678 }).SetReply (req )
693- c .setWithSubnet (resp , upstreamWithAddr , & net.IPNet {IP : ip2234 , Mask : mask16 }, l )
679+ c .setWithSubnet (resp , upstreamWithAddr , & net.IPNet {IP : ip2234 , Mask : mask16 }, testLogger )
694680
695681 // Add a response entry without subnet.
696682 resp = (& dns.Msg {
697683 Answer : []dns.RR {newRR (t , testFQDN , dns .TypeA , 1 , net.IP {3 , 3 , 3 , 3 })},
698684 }).SetReply (req )
699- c .setWithSubnet (resp , upstreamWithAddr , & net.IPNet {IP : nil , Mask : nil }, l )
685+ c .setWithSubnet (resp , upstreamWithAddr , & net.IPNet {IP : nil , Mask : nil }, testLogger )
700686
701687 t .Run ("with_subnet_1" , func (t * testing.T ) {
702688 ci , expired , key := c .getWithSubnet (req , & net.IPNet {IP : ip1234 , Mask : mask24 })
@@ -766,7 +752,7 @@ func TestCache_getWithSubnet_mask(t *testing.T) {
766752 resp ,
767753 upstreamWithAddr ,
768754 & net.IPNet {IP : cachedIP , Mask : cidrMask },
769- slogutil . NewDiscardLogger () ,
755+ testLogger ,
770756 )
771757
772758 t .Run ("mask_matched" , func (t * testing.T ) {
@@ -994,7 +980,7 @@ func TestCache_IsCacheable_negative(t *testing.T) {
994980
995981 for _ , tc := range testCases {
996982 t .Run (tc .name , func (t * testing.T ) {
997- assert .Equal (t , tc .wantTTL , cacheTTL (tc .req , slogutil . NewDiscardLogger () ))
983+ assert .Equal (t , tc .wantTTL , cacheTTL (tc .req , testLogger ))
998984 })
999985 }
1000986}
0 commit comments