From 6358240e9b0f10acdc05b470a64535df8cfcf67e Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Mon, 16 Nov 2020 15:52:05 +0300 Subject: [PATCH] Pull request: 2273 clean tests output Merge in DNS/adguard-home from 2273-clean-tests-output to master Closes #2273. Squashed commit of the following: commit 7571a33fc1f76300bd256578b3afa95338e399c4 Merge: f17df0f9c a19523b25 Author: Eugene Burkov Date: Mon Nov 16 15:45:30 2020 +0300 Merge branch 'master' into 2273-clean-tests-output commit f17df0f9ce2a3ed25db33fbc6a2e7cabd33f657b Author: Eugene Burkov Date: Mon Nov 16 15:35:42 2020 +0300 home: move build constraint on top line commit 3717c8ef5a51f9dcaa7e524bfa7b0f1d90bec93d Author: Eugene Burkov Date: Mon Nov 16 15:24:50 2020 +0300 all: add improvements to changelog commit de6d5afe39d74a3c3d3e0bbe6d0e09aea0214d56 Merge: 43d4f7acf 394fc5a9d Author: Eugene Burkov Date: Mon Nov 16 15:04:38 2020 +0300 Merge branch 'master' into 2273-clean-tests-output commit 43d4f7acf188e810aa7277cb6479110c9842e8be Author: Eugene Burkov Date: Mon Nov 16 13:38:13 2020 +0300 dnsfilter: remove redundant test logging commit 7194c1413006b8f52fc454e89ab052bf52e4e517 Author: Eugene Burkov Date: Mon Nov 16 12:19:14 2020 +0300 testutil: improve comments commit 9f17ab08e287fa69ce30d9e7eec8ea8880f87716 Author: Eugene Burkov Date: Sat Nov 14 01:22:08 2020 +0300 nclient4: fix wrong function name commit f355749149b2a4485792ba2bdcbc0bb4b629d726 Author: Eugene Burkov Date: Sat Nov 14 01:07:22 2020 +0300 testutil: fix comments and naming commit f8c50a260bfae08d594a7f37d603941d3680a45e Author: Eugene Burkov Date: Fri Nov 13 14:09:50 2020 +0300 testutil: create a package and include it commit f169cdc4084b719de65aa0cdc65200b48785322e Author: Eugene Burkov Date: Thu Nov 12 20:15:58 2020 +0300 agherr: discard loggers output commit 360e736b5a2a30f2c5350448234f14b841e3ea27 Author: Eugene Burkov Date: Thu Nov 12 20:09:55 2020 +0300 all: replace default log writer with ioutil.Discard Closes #2273. --- CHANGELOG.md | 6 +++++- internal/agherr/agherr_test.go | 5 +++++ internal/dhcpd/dhcpd_test.go | 5 +++++ internal/dhcpd/nclient4/client_test.go | 5 +++++ internal/dnsfilter/dnsfilter_test.go | 6 +++++- internal/dnsforward/dnsforward_test.go | 5 +++++ internal/home/auth_test.go | 7 +++++++ internal/home/home_test.go | 2 ++ internal/querylog/qlog_test.go | 5 +++++ internal/stats/stats_test.go | 5 +++++ internal/testutil/testutil.go | 19 +++++++++++++++++++ internal/update/update_test.go | 5 +++++ internal/util/auto_hosts_test.go | 5 +++++ 13 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 internal/testutil/testutil.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 63909d43..393a5e59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to - This changelog :-) (#2294). - `HACKING.md`, a guide for developers. +### Changed + +- Improved tests output (#2273). + ### Fixed -- Infinite loop in `/dhcp/find_active_dhcp` (#2301). +- Infinite loop in `/dhcp/find_active_dhcp` (#2301). \ No newline at end of file diff --git a/internal/agherr/agherr_test.go b/internal/agherr/agherr_test.go index 21e3af79..3940bdee 100644 --- a/internal/agherr/agherr_test.go +++ b/internal/agherr/agherr_test.go @@ -5,9 +5,14 @@ import ( "fmt" "testing" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + func TestError_Error(t *testing.T) { testCases := []struct { name string diff --git a/internal/dhcpd/dhcpd_test.go b/internal/dhcpd/dhcpd_test.go index c57ff36b..58b88bda 100644 --- a/internal/dhcpd/dhcpd_test.go +++ b/internal/dhcpd/dhcpd_test.go @@ -9,9 +9,14 @@ import ( "testing" "time" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + func testNotify(flags uint32) { } diff --git a/internal/dhcpd/nclient4/client_test.go b/internal/dhcpd/nclient4/client_test.go index 79501b28..353a9ed7 100644 --- a/internal/dhcpd/nclient4/client_test.go +++ b/internal/dhcpd/nclient4/client_test.go @@ -17,11 +17,16 @@ import ( "testing" "time" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/hugelgupf/socketpair" "github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4/server4" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + type handler struct { mu sync.Mutex received []*dhcpv4.DHCPv4 diff --git a/internal/dnsfilter/dnsfilter_test.go b/internal/dnsfilter/dnsfilter_test.go index f431a1e4..357e24c4 100644 --- a/internal/dnsfilter/dnsfilter_test.go +++ b/internal/dnsfilter/dnsfilter_test.go @@ -5,11 +5,16 @@ import ( "net" "testing" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/AdguardTeam/urlfilter/rules" "github.com/miekg/dns" "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + var setts RequestFilteringSettings // HELPERS @@ -290,7 +295,6 @@ func TestSafeSearchCacheGoogle(t *testing.T) { t.Fatalf("Failed to lookup for %s", safeDomain) } - t.Logf("IP addresses: %v", ips) ip := ips[0] for _, i := range ips { if i.To4() != nil { diff --git a/internal/dnsforward/dnsforward_test.go b/internal/dnsforward/dnsforward_test.go index 55a56d9a..ab2d1b72 100644 --- a/internal/dnsforward/dnsforward_test.go +++ b/internal/dnsforward/dnsforward_test.go @@ -18,6 +18,7 @@ import ( "testing" "time" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/AdguardTeam/AdGuardHome/internal/util" "github.com/AdguardTeam/AdGuardHome/internal/dhcpd" @@ -28,6 +29,10 @@ import ( "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + const ( tlsServerName = "testdns.adguard.com" testMessagesCount = 10 diff --git a/internal/home/auth_test.go b/internal/home/auth_test.go index a4829b93..dd2b68b3 100644 --- a/internal/home/auth_test.go +++ b/internal/home/auth_test.go @@ -9,9 +9,14 @@ import ( "testing" "time" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) @@ -85,9 +90,11 @@ type testResponseWriter struct { func (w *testResponseWriter) Header() http.Header { return w.hdr } + func (w *testResponseWriter) Write([]byte) (int, error) { return 0, nil } + func (w *testResponseWriter) WriteHeader(statusCode int) { w.statusCode = statusCode } diff --git a/internal/home/home_test.go b/internal/home/home_test.go index c78aee52..3a4db397 100644 --- a/internal/home/home_test.go +++ b/internal/home/home_test.go @@ -1,5 +1,7 @@ // +build !race +// TODO(e.burkov): remove this weird buildtag. + package home import ( diff --git a/internal/querylog/qlog_test.go b/internal/querylog/qlog_test.go index 078d39fe..35f33b99 100644 --- a/internal/querylog/qlog_test.go +++ b/internal/querylog/qlog_test.go @@ -8,10 +8,15 @@ import ( "github.com/AdguardTeam/dnsproxy/proxyutil" "github.com/AdguardTeam/AdGuardHome/internal/dnsfilter" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/miekg/dns" "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) diff --git a/internal/stats/stats_test.go b/internal/stats/stats_test.go index 21e728f3..3a4bed66 100644 --- a/internal/stats/stats_test.go +++ b/internal/stats/stats_test.go @@ -7,9 +7,14 @@ import ( "sync/atomic" "testing" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + func UIntArrayEquals(a, b []uint64) bool { if len(a) != len(b) { return false diff --git a/internal/testutil/testutil.go b/internal/testutil/testutil.go new file mode 100644 index 00000000..f5106265 --- /dev/null +++ b/internal/testutil/testutil.go @@ -0,0 +1,19 @@ +// Package testutil contains utilities for testing. +package testutil + +import ( + "io/ioutil" + "os" + "testing" + + "github.com/AdguardTeam/golibs/log" +) + +// DiscardLogOutput runs tests with discarded logger output. +func DiscardLogOutput(m *testing.M) { + // TODO(e.burkov): Refactor code and tests to not use the global mutable + // logger. + log.SetOutput(ioutil.Discard) + + os.Exit(m.Run()) +} diff --git a/internal/update/update_test.go b/internal/update/update_test.go index 44013960..5616104a 100644 --- a/internal/update/update_test.go +++ b/internal/update/update_test.go @@ -8,9 +8,14 @@ import ( "os" "testing" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + func startHTTPServer(data string) (net.Listener, uint16) { mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { diff --git a/internal/util/auto_hosts_test.go b/internal/util/auto_hosts_test.go index 9084daba..04911142 100644 --- a/internal/util/auto_hosts_test.go +++ b/internal/util/auto_hosts_test.go @@ -8,10 +8,15 @@ import ( "testing" "time" + "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/miekg/dns" "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + testutil.DiscardLogOutput(m) +} + func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir)