Skip to content

Commit

Permalink
all: upd testify, imp code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Mar 19, 2021
1 parent 8237c50 commit 0e2066b
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/cobra v1.1.3 // indirect
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
github.com/ti-mo/netfilter v0.4.0
github.com/u-root/u-root v7.0.0+incompatible
go.etcd.io/bbolt v1.3.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/ti-mo/netfilter v0.2.0/go.mod h1:8GbBGsY/8fxtyIdfwy29JiluNcPK4K7wIT+x42ipqUU=
Expand Down
2 changes: 1 addition & 1 deletion internal/aghnet/systemresolver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (sr *systemResolvers) getAddrs() (addrs []string, err error) {

// Don't close StdoutPipe since Wait do it for us in ¿most? cases.
//
// See go doc os/exec.StdoutPipe.
// See go doc os/exec.Cmd.StdoutPipe.

for _, addr := range possibleIPs {
if net.ParseIP(addr) == nil {
Expand Down
17 changes: 3 additions & 14 deletions internal/aghnet/systemresolvers_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ func (sr *systemResolvers) Refresh() (err error) {
return err
}

func newSystemResolvers(
refreshIvl time.Duration,
hostGenFunc HostGenFunc,
) (sr SystemResolvers) {
func newSystemResolvers(refreshIvl time.Duration, hostGenFunc HostGenFunc) (sr SystemResolvers) {
if hostGenFunc == nil {
hostGenFunc = defaultHostGen
}
Expand All @@ -68,19 +65,11 @@ func (sr *systemResolvers) dialFunc(_ context.Context, _, address string) (_ net
if err != nil {
// TODO(e.burkov): Maybe use a structured badAddrPassedErr to
// allow unwrapping of the real error.
return nil, fmt.Errorf(
"systemResolvers: %s: %w",
err,
badAddrPassedErr,
)
return nil, fmt.Errorf("%s: %w", err, badAddrPassedErr)
}

if net.ParseIP(host) == nil {
return nil, fmt.Errorf(
"systemResolvers: parsing %q: %w",
host,
badAddrPassedErr,
)
return nil, fmt.Errorf("parsing %q: %w", host, badAddrPassedErr)
}

sr.addrsLock.Lock()
Expand Down
3 changes: 1 addition & 2 deletions internal/aghnet/systemresolvers_others_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package aghnet

import (
"context"
"errors"
"testing"
"time"

Expand Down Expand Up @@ -69,7 +68,7 @@ func TestSystemResolvers_DialFunc(t *testing.T) {
conn, err := imp.dialFunc(context.Background(), "", tc.address)

require.Nil(t, conn)
assert.True(t, errors.Is(err, tc.want))
assert.ErrorIs(t, err, tc.want)
})
}
}
2 changes: 2 additions & 0 deletions internal/aghnet/systemresolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ func TestSystemResolvers_Get(t *testing.T) {
}

// TODO(e.burkov): Write tests for refreshWithTicker.
//
// See https://github.com/AdguardTeam/AdGuardHome/issues/2846.
2 changes: 2 additions & 0 deletions internal/aghnet/systemresolvers_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
package aghnet

// TODO(e.burkov): Write tests for Windows implementation.
//
// See https://github.com/AdguardTeam/AdGuardHome/issues/2846.
3 changes: 1 addition & 2 deletions internal/querylog/qlogreader_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package querylog

import (
"errors"
"io"
"testing"
"time"
Expand Down Expand Up @@ -116,7 +115,7 @@ func TestQLogReader_Seek(t *testing.T) {
require.Nil(t, err)

err = r.SeekTS(ts.UnixNano())
assert.True(t, errors.Is(err, tc.want), err)
assert.ErrorIs(t, err, tc.want)
})
}
}
Expand Down

0 comments on commit 0e2066b

Please sign in to comment.