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 <e.burkov@adguard.com>
Date:   Mon Nov 16 15:45:30 2020 +0300

    Merge branch 'master' into 2273-clean-tests-output

commit f17df0f9ce2a3ed25db33fbc6a2e7cabd33f657b
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Mon Nov 16 15:35:42 2020 +0300

    home: move build constraint on top line

commit 3717c8ef5a51f9dcaa7e524bfa7b0f1d90bec93d
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Mon Nov 16 15:24:50 2020 +0300

    all: add improvements to changelog

commit de6d5afe39d74a3c3d3e0bbe6d0e09aea0214d56
Merge: 43d4f7acf 394fc5a9d
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Mon Nov 16 15:04:38 2020 +0300

    Merge branch 'master' into 2273-clean-tests-output

commit 43d4f7acf188e810aa7277cb6479110c9842e8be
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Mon Nov 16 13:38:13 2020 +0300

    dnsfilter: remove redundant test logging

commit 7194c1413006b8f52fc454e89ab052bf52e4e517
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Mon Nov 16 12:19:14 2020 +0300

    testutil: improve comments

commit 9f17ab08e287fa69ce30d9e7eec8ea8880f87716
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Sat Nov 14 01:22:08 2020 +0300

    nclient4: fix wrong function name

commit f355749149b2a4485792ba2bdcbc0bb4b629d726
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Sat Nov 14 01:07:22 2020 +0300

    testutil: fix comments and naming

commit f8c50a260bfae08d594a7f37d603941d3680a45e
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Fri Nov 13 14:09:50 2020 +0300

    testutil: create a package and include it

commit f169cdc4084b719de65aa0cdc65200b48785322e
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Thu Nov 12 20:15:58 2020 +0300

    agherr: discard loggers output

commit 360e736b5a2a30f2c5350448234f14b841e3ea27
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Thu Nov 12 20:09:55 2020 +0300

    all: replace default log writer with ioutil.Discard

    Closes #2273.
This commit is contained in:
Eugene Burkov 2020-11-16 15:52:05 +03:00
parent a19523b258
commit 6358240e9b
13 changed files with 78 additions and 2 deletions

View File

@ -14,6 +14,10 @@ and this project adheres to
- This changelog :-) (#2294). - This changelog :-) (#2294).
- `HACKING.md`, a guide for developers. - `HACKING.md`, a guide for developers.
### Changed
- Improved tests output (#2273).
### Fixed ### Fixed
- Infinite loop in `/dhcp/find_active_dhcp` (#2301). - Infinite loop in `/dhcp/find_active_dhcp` (#2301).

View File

@ -5,9 +5,14 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
func TestError_Error(t *testing.T) { func TestError_Error(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string

View File

@ -9,9 +9,14 @@ import (
"testing" "testing"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
func testNotify(flags uint32) { func testNotify(flags uint32) {
} }

View File

@ -17,11 +17,16 @@ import (
"testing" "testing"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
"github.com/hugelgupf/socketpair" "github.com/hugelgupf/socketpair"
"github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv4/server4" "github.com/insomniacslk/dhcp/dhcpv4/server4"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
type handler struct { type handler struct {
mu sync.Mutex mu sync.Mutex
received []*dhcpv4.DHCPv4 received []*dhcpv4.DHCPv4

View File

@ -5,11 +5,16 @@ import (
"net" "net"
"testing" "testing"
"github.com/AdguardTeam/AdGuardHome/internal/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"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
var setts RequestFilteringSettings var setts RequestFilteringSettings
// HELPERS // HELPERS
@ -290,7 +295,6 @@ func TestSafeSearchCacheGoogle(t *testing.T) {
t.Fatalf("Failed to lookup for %s", safeDomain) t.Fatalf("Failed to lookup for %s", safeDomain)
} }
t.Logf("IP addresses: %v", ips)
ip := ips[0] ip := ips[0]
for _, i := range ips { for _, i := range ips {
if i.To4() != nil { if i.To4() != nil {

View File

@ -18,6 +18,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
"github.com/AdguardTeam/AdGuardHome/internal/util" "github.com/AdguardTeam/AdGuardHome/internal/util"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd" "github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
@ -28,6 +29,10 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
const ( const (
tlsServerName = "testdns.adguard.com" tlsServerName = "testdns.adguard.com"
testMessagesCount = 10 testMessagesCount = 10

View File

@ -9,9 +9,14 @@ import (
"testing" "testing"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
func prepareTestDir() string { func prepareTestDir() string {
const dir = "./agh-test" const dir = "./agh-test"
_ = os.RemoveAll(dir) _ = os.RemoveAll(dir)
@ -85,9 +90,11 @@ type testResponseWriter struct {
func (w *testResponseWriter) Header() http.Header { func (w *testResponseWriter) Header() http.Header {
return w.hdr return w.hdr
} }
func (w *testResponseWriter) Write([]byte) (int, error) { func (w *testResponseWriter) Write([]byte) (int, error) {
return 0, nil return 0, nil
} }
func (w *testResponseWriter) WriteHeader(statusCode int) { func (w *testResponseWriter) WriteHeader(statusCode int) {
w.statusCode = statusCode w.statusCode = statusCode
} }

View File

@ -1,5 +1,7 @@
// +build !race // +build !race
// TODO(e.burkov): remove this weird buildtag.
package home package home
import ( import (

View File

@ -8,10 +8,15 @@ import (
"github.com/AdguardTeam/dnsproxy/proxyutil" "github.com/AdguardTeam/dnsproxy/proxyutil"
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter" "github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
"github.com/miekg/dns" "github.com/miekg/dns"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
func prepareTestDir() string { func prepareTestDir() string {
const dir = "./agh-test" const dir = "./agh-test"
_ = os.RemoveAll(dir) _ = os.RemoveAll(dir)

View File

@ -7,9 +7,14 @@ import (
"sync/atomic" "sync/atomic"
"testing" "testing"
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
func UIntArrayEquals(a, b []uint64) bool { func UIntArrayEquals(a, b []uint64) bool {
if len(a) != len(b) { if len(a) != len(b) {
return false return false

View File

@ -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())
}

View File

@ -8,9 +8,14 @@ import (
"os" "os"
"testing" "testing"
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
func startHTTPServer(data string) (net.Listener, uint16) { func startHTTPServer(data string) (net.Listener, uint16) {
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {

View File

@ -8,10 +8,15 @@ import (
"testing" "testing"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
"github.com/miekg/dns" "github.com/miekg/dns"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
func prepareTestDir() string { func prepareTestDir() string {
const dir = "./agh-test" const dir = "./agh-test"
_ = os.RemoveAll(dir) _ = os.RemoveAll(dir)