From 07b8131547fd32bd37693ced4443374b556e5c13 Mon Sep 17 00:00:00 2001 From: Dimitry Kolyshev Date: Wed, 17 Jul 2024 14:06:44 +0300 Subject: [PATCH] Pull request: AGDNS-2202-slog-imp-tests Squashed commit of the following: commit d4ebf59dd4fa7944150b480e6a1379ff929636a1 Merge: 63104ef 50640fb Author: Dimitry Kolyshev Date: Wed Jul 17 13:31:08 2024 +0300 Merge remote-tracking branch 'origin/master' into AGDNS-2202-slog-imp-tests commit 63104ef1af375a410ee02ecce82801cbcd60cc45 Author: Dimitry Kolyshev Date: Wed Jul 17 12:20:02 2024 +0300 proxy: imp tests commit 22fdf0c0be1aa7530018ab0b9f86142fc96828bd Author: Dimitry Kolyshev Date: Wed Jul 17 11:13:51 2024 +0300 upstream: imp tests commit 5ec88635ee95ec6aa87158eb726ac312ba5c2750 Author: Dimitry Kolyshev Date: Wed Jul 17 11:13:23 2024 +0300 proxy: imp tests --- proxy/beforerequest_test.go | 2 ++ proxy/bogusnxdomain_test.go | 2 ++ proxy/cache_test.go | 3 +++ proxy/dns64_test.go | 3 +++ proxy/exchange_internal_test.go | 2 ++ proxy/handler_test.go | 2 ++ proxy/lookup_test.go | 1 + proxy/proxy_test.go | 13 +++++++++++++ proxy/ratelimit_test.go | 2 ++ proxy/server_dnscrypt_test.go | 7 +++++++ proxy/server_https_test.go | 2 ++ proxy/server_quic_test.go | 3 +++ proxy/server_tcp_test.go | 2 ++ upstream/upstream_internal_test.go | 1 + 14 files changed, 45 insertions(+) diff --git a/proxy/beforerequest_test.go b/proxy/beforerequest_test.go index 19acc6870..c8426342e 100644 --- a/proxy/beforerequest_test.go +++ b/proxy/beforerequest_test.go @@ -9,6 +9,7 @@ import ( "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/errors" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/netutil" "github.com/AdguardTeam/golibs/testutil" "github.com/miekg/dns" @@ -52,6 +53,7 @@ func TestProxy_HandleDNSRequest_beforeRequestHandler(t *testing.T) { errorResponse := (&dns.Msg{}).SetReply(errorRequest) p := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: &UpstreamConfig{ Upstreams: []upstream.Upstream{&fakeUpstream{ diff --git a/proxy/bogusnxdomain_test.go b/proxy/bogusnxdomain_test.go index b54500807..ff45845dc 100644 --- a/proxy/bogusnxdomain_test.go +++ b/proxy/bogusnxdomain_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/AdguardTeam/dnsproxy/upstream" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/testutil" "github.com/miekg/dns" "github.com/stretchr/testify/assert" @@ -15,6 +16,7 @@ import ( func TestProxy_IsBogusNXDomain(t *testing.T) { prx := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), diff --git a/proxy/cache_test.go b/proxy/cache_test.go index 34dae394d..bc6260a61 100644 --- a/proxy/cache_test.go +++ b/proxy/cache_test.go @@ -32,6 +32,7 @@ var upstreamWithAddr = &fakeUpstream{ func TestServeCached(t *testing.T) { dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), @@ -288,6 +289,7 @@ func TestCacheExpiration(t *testing.T) { t.Parallel() dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), @@ -347,6 +349,7 @@ func TestCacheExpirationWithTTLOverride(t *testing.T) { u := testUpstream{} dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: &UpstreamConfig{ diff --git a/proxy/dns64_test.go b/proxy/dns64_test.go index c5605ffb2..8f6d0bb10 100644 --- a/proxy/dns64_test.go +++ b/proxy/dns64_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/AdguardTeam/dnsproxy/upstream" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/netutil" "github.com/AdguardTeam/golibs/testutil" "github.com/miekg/dns" @@ -38,6 +39,7 @@ func TestDNS64Race(t *testing.T) { } dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, PrivateSubnets: netutil.SubnetSetFunc(netutil.IsLocallyServed), @@ -355,6 +357,7 @@ func TestProxy_Resolve_dns64(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { p := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: &UpstreamConfig{ diff --git a/proxy/exchange_internal_test.go b/proxy/exchange_internal_test.go index 8d8805b6f..8cb2c5efa 100644 --- a/proxy/exchange_internal_test.go +++ b/proxy/exchange_internal_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/AdguardTeam/dnsproxy/upstream" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/netutil" "github.com/miekg/dns" "github.com/stretchr/testify/assert" @@ -215,6 +216,7 @@ func TestProxy_Exchange_loadBalance(t *testing.T) { } p := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: &UpstreamConfig{ diff --git a/proxy/handler_test.go b/proxy/handler_test.go index 40756e5cd..8232a40eb 100644 --- a/proxy/handler_test.go +++ b/proxy/handler_test.go @@ -6,6 +6,7 @@ import ( "sync" "testing" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/testutil" "github.com/miekg/dns" "github.com/stretchr/testify/assert" @@ -19,6 +20,7 @@ func TestFilteringHandler(t *testing.T) { // Prepare the proxy server dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), diff --git a/proxy/lookup_test.go b/proxy/lookup_test.go index cbe7f0acd..f011f0074 100644 --- a/proxy/lookup_test.go +++ b/proxy/lookup_test.go @@ -23,6 +23,7 @@ func TestLookupNetIP(t *testing.T) { require.NoError(t, err) conf := &Config{ + Logger: slogutil.NewDiscardLogger(), UpstreamConfig: &UpstreamConfig{ Upstreams: []upstream.Upstream{dnsUpstream}, }, diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go index ce7290665..e380e5dff 100644 --- a/proxy/proxy_test.go +++ b/proxy/proxy_test.go @@ -261,6 +261,7 @@ func mustStartDefaultProxy(t *testing.T) (p *Proxy) { t.Helper() p = mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), @@ -288,6 +289,7 @@ func TestProxyRace(t *testing.T) { testDefaultUpstreamAddr, ) dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: upsConf, @@ -487,6 +489,7 @@ func TestProxy_Resolve_dnssecCache(t *testing.T) { } p := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: &UpstreamConfig{Upstreams: []upstream.Upstream{u}}, @@ -583,6 +586,7 @@ func TestExchangeWithReservedDomains(t *testing.T) { t.Parallel() dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfigWithBoot( @@ -652,6 +656,7 @@ func TestOneByOneUpstreamsExchange(t *testing.T) { t.Parallel() dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfigWithBoot( @@ -745,6 +750,7 @@ func TestFallback(t *testing.T) { }).String() dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig( @@ -842,6 +848,7 @@ func TestFallbackFromInvalidBootstrap(t *testing.T) { require.NoError(t, err) dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: upsConf, @@ -883,6 +890,7 @@ func TestFallbackFromInvalidBootstrap(t *testing.T) { func TestRefuseAny(t *testing.T) { dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), @@ -921,6 +929,7 @@ func TestRefuseAny(t *testing.T) { func TestInvalidDNSRequest(t *testing.T) { dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), @@ -1093,6 +1102,7 @@ func TestExchangeCustomUpstreamConfig(t *testing.T) { func TestExchangeCustomUpstreamConfigCache(t *testing.T) { prx := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), @@ -1224,6 +1234,7 @@ func TestECSProxy(t *testing.T) { } prx := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: &UpstreamConfig{ @@ -1333,6 +1344,7 @@ func TestECSProxyCacheMinMaxTTL(t *testing.T) { } prx := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: &UpstreamConfig{Upstreams: []upstream.Upstream{u}}, @@ -1576,6 +1588,7 @@ func TestProxy_HandleDNSRequest_private(t *testing.T) { } p := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: &UpstreamConfig{ Upstreams: []upstream.Upstream{generalUps}, diff --git a/proxy/ratelimit_test.go b/proxy/ratelimit_test.go index 975404391..5bea0c409 100644 --- a/proxy/ratelimit_test.go +++ b/proxy/ratelimit_test.go @@ -6,6 +6,7 @@ import ( "net/netip" "testing" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/testutil" "github.com/miekg/dns" "github.com/stretchr/testify/require" @@ -13,6 +14,7 @@ import ( func TestRatelimitingProxy(t *testing.T) { dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), diff --git a/proxy/server_dnscrypt_test.go b/proxy/server_dnscrypt_test.go index e6d3157e1..b8e5b7979 100644 --- a/proxy/server_dnscrypt_test.go +++ b/proxy/server_dnscrypt_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/testutil" "github.com/ameshkov/dnscrypt/v2" "github.com/ameshkov/dnsstamps" @@ -14,6 +15,11 @@ import ( "github.com/stretchr/testify/require" ) +// TODO(d.kolyshev): Remove this after migrating dnscrypt to slog. +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + func getFreePort() uint { l, _ := net.Listen("tcp", "127.0.0.1:0") port := uint(l.Addr().(*net.TCPAddr).Port) @@ -35,6 +41,7 @@ func createTestDNSCryptProxy(t *testing.T) (*Proxy, dnscrypt.ResolverConfig) { port := getFreePort() p := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), DNSCryptUDPListenAddr: []*net.UDPAddr{{ Port: int(port), IP: net.ParseIP(listenIP), }}, diff --git a/proxy/server_https_test.go b/proxy/server_https_test.go index 3792baf58..a968d95e4 100644 --- a/proxy/server_https_test.go +++ b/proxy/server_https_test.go @@ -39,6 +39,7 @@ func TestHttpsProxy(t *testing.T) { t.Run(tc.name, func(t *testing.T) { tlsConf, caPem := newTLSConfig(t) dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), TLSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, HTTPSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, @@ -80,6 +81,7 @@ func TestProxy_trustedProxies(t *testing.T) { // Prepare the proxy server. tlsConf, caPem := newTLSConfig(t) dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), TLSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, HTTPSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, diff --git a/proxy/server_quic_test.go b/proxy/server_quic_test.go index d6181a699..1e44ded6c 100644 --- a/proxy/server_quic_test.go +++ b/proxy/server_quic_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/AdguardTeam/dnsproxy/proxyutil" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/testutil" "github.com/miekg/dns" "github.com/quic-go/quic-go" @@ -28,6 +29,7 @@ func TestQuicProxy(t *testing.T) { } conf := &Config{ + Logger: slogutil.NewDiscardLogger(), QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, TLSConfig: serverConfig, UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr), @@ -89,6 +91,7 @@ func TestQuicProxy(t *testing.T) { func TestQuicProxy_largePackets(t *testing.T) { serverConfig, caPem := newTLSConfig(t) dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), TLSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, HTTPSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, diff --git a/proxy/server_tcp_test.go b/proxy/server_tcp_test.go index 1a4240cea..5441766b8 100644 --- a/proxy/server_tcp_test.go +++ b/proxy/server_tcp_test.go @@ -7,6 +7,7 @@ import ( "net" "testing" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/testutil" "github.com/miekg/dns" "github.com/stretchr/testify/require" @@ -26,6 +27,7 @@ func TestTcpProxy(t *testing.T) { func TestTlsProxy(t *testing.T) { serverConfig, caPem := newTLSConfig(t) dnsProxy := mustNew(t, &Config{ + Logger: slogutil.NewDiscardLogger(), TLSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, HTTPSListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)}, QUICListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)}, diff --git a/upstream/upstream_internal_test.go b/upstream/upstream_internal_test.go index 78e5d1fe9..e2421a039 100644 --- a/upstream/upstream_internal_test.go +++ b/upstream/upstream_internal_test.go @@ -28,6 +28,7 @@ import ( // TODO(ameshkov): Make tests here not depend on external servers. +// TODO(d.kolyshev): Remove this after migrating dnscrypt to slog. func TestMain(m *testing.M) { testutil.DiscardLogOutput(m) }