Pull request: imp-tests
Merge in DNS/adguard-home from imp-tests to master Squashed commit of the following: commit ea5b4e7a93359ae4800f75e77d02944a4f5d2df8 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Oct 27 15:12:45 2022 +0300 all: imp tests, use testutil
This commit is contained in:
parent
9951d861d1
commit
9c9d6b48e3
|
@ -11,7 +11,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
|
||||||
"github.com/AdguardTeam/golibs/errors"
|
"github.com/AdguardTeam/golibs/errors"
|
||||||
"github.com/AdguardTeam/golibs/netutil"
|
"github.com/AdguardTeam/golibs/netutil"
|
||||||
"github.com/AdguardTeam/golibs/testutil"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
|
@ -20,7 +19,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testdata is the filesystem containing data for testing the package.
|
// testdata is the filesystem containing data for testing the package.
|
||||||
|
@ -196,10 +195,7 @@ func TestCheckPort(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testutil.CleanupAndRequireSuccess(t, l.Close)
|
testutil.CleanupAndRequireSuccess(t, l.Close)
|
||||||
|
|
||||||
addr := l.Addr()
|
ipp := testutil.RequireTypeAssert[*net.TCPAddr](t, l.Addr()).AddrPort()
|
||||||
require.IsType(t, new(net.TCPAddr), addr)
|
|
||||||
|
|
||||||
ipp := addr.(*net.TCPAddr).AddrPort()
|
|
||||||
require.Equal(t, laddr.Addr(), ipp.Addr())
|
require.Equal(t, laddr.Addr(), ipp.Addr())
|
||||||
require.NotZero(t, ipp.Port())
|
require.NotZero(t, ipp.Port())
|
||||||
|
|
||||||
|
@ -215,10 +211,7 @@ func TestCheckPort(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testutil.CleanupAndRequireSuccess(t, conn.Close)
|
testutil.CleanupAndRequireSuccess(t, conn.Close)
|
||||||
|
|
||||||
addr := conn.LocalAddr()
|
ipp := testutil.RequireTypeAssert[*net.UDPAddr](t, conn.LocalAddr()).AddrPort()
|
||||||
require.IsType(t, new(net.UDPAddr), addr)
|
|
||||||
|
|
||||||
ipp := addr.(*net.UDPAddr).AddrPort()
|
|
||||||
require.Equal(t, laddr.Addr(), ipp.Addr())
|
require.Equal(t, laddr.Addr(), ipp.Addr())
|
||||||
require.NotZero(t, ipp.Port())
|
require.NotZero(t, ipp.Port())
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -17,9 +18,8 @@ func createTestSystemResolversImpl(
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
sr := createTestSystemResolvers(t, hostGenFunc)
|
sr := createTestSystemResolvers(t, hostGenFunc)
|
||||||
require.IsType(t, (*systemResolvers)(nil), sr)
|
|
||||||
|
|
||||||
return sr.(*systemResolvers)
|
return testutil.RequireTypeAssert[*systemResolvers](t, sr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSystemResolvers_Refresh(t *testing.T) {
|
func TestSystemResolvers_Refresh(t *testing.T) {
|
||||||
|
|
|
@ -3,9 +3,9 @@ package aghos_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,23 +3,11 @@ package aghtest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DiscardLogOutput runs tests with discarded logger output.
|
|
||||||
//
|
|
||||||
// TODO(a.garipov): Replace with testutil.
|
|
||||||
func DiscardLogOutput(m *testing.M) {
|
|
||||||
// TODO(e.burkov): Refactor code and tests to not use the global mutable
|
|
||||||
// logger.
|
|
||||||
log.SetOutput(io.Discard)
|
|
||||||
|
|
||||||
os.Exit(m.Run())
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReplaceLogWriter moves logger output to w and uses Cleanup method of t to
|
// ReplaceLogWriter moves logger output to w and uses Cleanup method of t to
|
||||||
// revert changes.
|
// revert changes.
|
||||||
func ReplaceLogWriter(t testing.TB, w io.Writer) {
|
func ReplaceLogWriter(t testing.TB, w io.Writer) {
|
||||||
|
|
|
@ -4,14 +4,13 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtls"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtls"
|
||||||
"github.com/AdguardTeam/golibs/testutil"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseCiphers(t *testing.T) {
|
func TestParseCiphers(t *testing.T) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
|
||||||
"github.com/AdguardTeam/golibs/testutil"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -17,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNotify(flags uint32) {
|
func testNotify(flags uint32) {
|
||||||
|
|
|
@ -482,7 +482,6 @@ func TestV4Server_updateOptions(t *testing.T) {
|
||||||
|
|
||||||
s, err := v4Create(conf)
|
s, err := v4Create(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.IsType(t, (*v4Server)(nil), s)
|
require.IsType(t, (*v4Server)(nil), s)
|
||||||
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/aghalg"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
|
@ -449,12 +450,27 @@ func TestServer_ProcessDHCPHosts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_ProcessRestrictLocal(t *testing.T) {
|
func TestServer_ProcessRestrictLocal(t *testing.T) {
|
||||||
ups := &aghtest.Upstream{
|
const (
|
||||||
Reverse: map[string][]string{
|
extPTRQuestion = "251.252.253.254.in-addr.arpa."
|
||||||
"251.252.253.254.in-addr.arpa.": {"host1.example.net."},
|
extPTRAnswer = "host1.example.net."
|
||||||
"1.1.168.192.in-addr.arpa.": {"some.local-client."},
|
intPTRQuestion = "1.1.168.192.in-addr.arpa."
|
||||||
|
intPTRAnswer = "some.local-client."
|
||||||
|
)
|
||||||
|
|
||||||
|
ups := &aghtest.UpstreamMock{
|
||||||
|
OnAddress: func() (addr string) { return "upstream.example" },
|
||||||
|
OnExchange: func(req *dns.Msg) (resp *dns.Msg, err error) {
|
||||||
|
resp = aghalg.Coalesce(
|
||||||
|
aghtest.RespondTo(t, req, dns.ClassINET, dns.TypePTR, extPTRQuestion, extPTRAnswer),
|
||||||
|
aghtest.RespondTo(t, req, dns.ClassINET, dns.TypePTR, intPTRQuestion, intPTRAnswer),
|
||||||
|
new(dns.Msg).SetRcode(req, dns.RcodeNameError),
|
||||||
|
)
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
},
|
},
|
||||||
|
OnClose: func() (err error) { return nil },
|
||||||
}
|
}
|
||||||
|
|
||||||
s := createTestServer(t, &filtering.Config{}, ServerConfig{
|
s := createTestServer(t, &filtering.Config{}, ServerConfig{
|
||||||
UDPListenAddrs: []*net.UDPAddr{{}},
|
UDPListenAddrs: []*net.UDPAddr{{}},
|
||||||
TCPListenAddrs: []*net.TCPAddr{{}},
|
TCPListenAddrs: []*net.TCPAddr{{}},
|
||||||
|
@ -524,14 +540,26 @@ func TestServer_ProcessLocalPTR_usingResolvers(t *testing.T) {
|
||||||
const locDomain = "some.local."
|
const locDomain = "some.local."
|
||||||
const reqAddr = "1.1.168.192.in-addr.arpa."
|
const reqAddr = "1.1.168.192.in-addr.arpa."
|
||||||
|
|
||||||
s := createTestServer(t, &filtering.Config{}, ServerConfig{
|
s := createTestServer(
|
||||||
UDPListenAddrs: []*net.UDPAddr{{}},
|
t,
|
||||||
TCPListenAddrs: []*net.TCPAddr{{}},
|
&filtering.Config{},
|
||||||
}, &aghtest.Upstream{
|
ServerConfig{
|
||||||
Reverse: map[string][]string{
|
UDPListenAddrs: []*net.UDPAddr{{}},
|
||||||
reqAddr: {locDomain},
|
TCPListenAddrs: []*net.TCPAddr{{}},
|
||||||
},
|
},
|
||||||
})
|
&aghtest.UpstreamMock{
|
||||||
|
OnAddress: func() (addr string) { return "upstream.example" },
|
||||||
|
OnExchange: func(req *dns.Msg) (resp *dns.Msg, err error) {
|
||||||
|
resp = aghalg.Coalesce(
|
||||||
|
aghtest.RespondTo(t, req, dns.ClassINET, dns.TypePTR, reqAddr, locDomain),
|
||||||
|
new(dns.Msg).SetRcode(req, dns.RcodeNameError),
|
||||||
|
)
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
},
|
||||||
|
OnClose: func() (err error) { return nil },
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
var proxyCtx *proxy.DNSContext
|
var proxyCtx *proxy.DNSContext
|
||||||
var dnsCtx *dnsContext
|
var dnsCtx *dnsContext
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||||
"github.com/AdguardTeam/golibs/cache"
|
"github.com/AdguardTeam/golibs/cache"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/AdguardTeam/urlfilter/rules"
|
"github.com/AdguardTeam/urlfilter/rules"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -18,7 +19,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -3,10 +3,10 @@ package home
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
initCmdLineOpts()
|
initCmdLineOpts()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,14 @@ import (
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/next/dnssvc"
|
"github.com/AdguardTeam/AdGuardHome/internal/next/dnssvc"
|
||||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||||
"github.com/AdguardTeam/golibs/errors"
|
"github.com/AdguardTeam/golibs/errors"
|
||||||
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testTimeout is the common timeout for tests.
|
// testTimeout is the common timeout for tests.
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
|
"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/next/dnssvc"
|
"github.com/AdguardTeam/AdGuardHome/internal/next/dnssvc"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/next/websvc"
|
"github.com/AdguardTeam/AdGuardHome/internal/next/websvc"
|
||||||
|
@ -21,7 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testTimeout is the common timeout for tests.
|
// testTimeout is the common timeout for tests.
|
||||||
|
|
|
@ -8,9 +8,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/dnsproxy/proxyutil"
|
"github.com/AdguardTeam/dnsproxy/proxyutil"
|
||||||
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/AdguardTeam/golibs/timeutil"
|
"github.com/AdguardTeam/golibs/timeutil"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -18,7 +18,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestQueryLog tests adding and loading (with filtering) entries from disk and
|
// TestQueryLog tests adding and loading (with filtering) entries from disk and
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
||||||
"github.com/AdguardTeam/golibs/testutil"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -18,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// constUnitID is the UnitIDGenFunc which always return 0.
|
// constUnitID is the UnitIDGenFunc which always return 0.
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghalg"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghalg"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/version"
|
"github.com/AdguardTeam/AdGuardHome/internal/version"
|
||||||
"github.com/AdguardTeam/golibs/testutil"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -21,7 +20,7 @@ import (
|
||||||
// TODO(a.garipov): Rewrite these tests.
|
// TODO(a.garipov): Rewrite these tests.
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
aghtest.DiscardLogOutput(m)
|
testutil.DiscardLogOutput(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startHTTPServer(data string) (l net.Listener, portStr string) {
|
func startHTTPServer(data string) (l net.Listener, portStr string) {
|
||||||
|
|
Loading…
Reference in New Issue