Skip to content

Commit

Permalink
Pull request: 2273 clean tests output
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from 2273-clean-tests-output to master

Closes #2273.

Squashed commit of the following:

commit 7571a33
Merge: f17df0f a19523b
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 f17df0f
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Mon Nov 16 15:35:42 2020 +0300

    home: move build constraint on top line

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

    all: add improvements to changelog

commit de6d5af
Merge: 43d4f7a 394fc5a
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 43d4f7a
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Mon Nov 16 13:38:13 2020 +0300

    dnsfilter: remove redundant test logging

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

    testutil: improve comments

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

    nclient4: fix wrong function name

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

    testutil: fix comments and naming

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

    testutil: create a package and include it

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

    agherr: discard loggers output

commit 360e736
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.
  • Loading branch information
EugeneOne1 authored and Blakhard committed Dec 10, 2020
1 parent ea170aa commit ce0eebb
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
5 changes: 5 additions & 0 deletions internal/agherr/agherr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/dhcpd/dhcpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down
5 changes: 5 additions & 0 deletions internal/dhcpd/nclient4/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion internal/dnsfilter/dnsfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions internal/dnsforward/dnsforward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions internal/home/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions internal/home/home_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// +build !race

// TODO(e.burkov): remove this weird buildtag.

package home

import (
Expand Down
5 changes: 5 additions & 0 deletions internal/querylog/qlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions internal/stats/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions internal/testutil/testutil.go
Original file line number Diff line number Diff line change
@@ -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())
}
5 changes: 5 additions & 0 deletions internal/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions internal/util/auto_hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ce0eebb

Please sign in to comment.