Pull request: 2846 cover aghnet vol.2
Merge in DNS/adguard-home from 2846-cover-aghnet-vol.2 to master
Updates #2846.
Closes #4408.
Squashed commit of the following:
commit 8d62b29d5b5be875cb71e518e479e321d853eb1a
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Mar 23 20:42:04 2022 +0300
home: recover panic
commit 1d98109e910830bec712c7aecbbbcb8f659d823d
Merge: ac11d751 9ce2a0fb
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Mar 23 20:32:05 2022 +0300
Merge branch 'master' into 2846-cover-aghnet-vol.2
commit ac11d751fb7951e3dd0940bf425a893223c32789
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Mar 23 20:29:41 2022 +0300
aghnet: use iotest
commit 7c923df7bafd5d4b91c4b4a01e75ab161944f949
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Mar 23 20:17:19 2022 +0300
aghnet: cover more
commit 3bfd4d587e4b887b5527d60c0eb6027da15c7e37
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Mar 23 14:13:59 2022 +0300
aghnet: cover arpdb more
commit cd5cf7bbdecceeab6d3abee10a5572e1e907cc67
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Mar 23 13:05:35 2022 +0300
all: rm arpdb initial refresh
commit 0fb8d9e44a4d130ca4e8fc2ea5d595ec08555302
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Mar 22 21:13:16 2022 +0300
aghnet: cover arpdb
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"testing/iotest"
|
||||
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/testutil"
|
||||
@@ -13,6 +14,15 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewARPDB(t *testing.T) {
|
||||
var a ARPDB
|
||||
require.NotPanics(t, func() {
|
||||
a = NewARPDB()
|
||||
})
|
||||
|
||||
assert.NotNil(t, a)
|
||||
}
|
||||
|
||||
// TestARPDB is the mock implementation of ARPDB to use in tests.
|
||||
type TestARPDB struct {
|
||||
OnRefresh func() (err error)
|
||||
@@ -166,3 +176,46 @@ func TestCmdARPDB_arpa(t *testing.T) {
|
||||
testutil.AssertErrorMsg(t, "cmd arpdb: running command: can't run", err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCmdARPDB_errors(t *testing.T) {
|
||||
const errRead errors.Error = "can't read"
|
||||
|
||||
badReaderRunCmd := runCmdFunc(func() (r io.Reader, err error) {
|
||||
return iotest.ErrReader(errRead), nil
|
||||
})
|
||||
|
||||
a := &cmdARPDB{
|
||||
runcmd: badReaderRunCmd,
|
||||
parse: parseArpA,
|
||||
ns: &neighs{
|
||||
mu: &sync.RWMutex{},
|
||||
ns: make([]Neighbor, 0),
|
||||
},
|
||||
}
|
||||
|
||||
const wantErrMsg string = "cmd arpdb: scanning the output: " + string(errRead)
|
||||
|
||||
testutil.AssertErrorMsg(t, wantErrMsg, a.Refresh())
|
||||
}
|
||||
|
||||
func TestEmptyARPDB(t *testing.T) {
|
||||
a := EmptyARPDB{}
|
||||
|
||||
t.Run("refresh", func(t *testing.T) {
|
||||
var err error
|
||||
require.NotPanics(t, func() {
|
||||
err = a.Refresh()
|
||||
})
|
||||
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("neighbors", func(t *testing.T) {
|
||||
var ns []Neighbor
|
||||
require.NotPanics(t, func() {
|
||||
ns = a.Neighbors()
|
||||
})
|
||||
|
||||
assert.Empty(t, ns)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user