Pull request: all: imp some tests

Merge in DNS/adguard-home from imp-tests to master

Squashed commit of the following:

commit 6171420068d66808f069f280a81e0c60e61e5ce3
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Mar 25 17:43:36 2021 +0300

    aghnet: imp test msgs

commit ed2880ff03ab0e41a77f07aad2caf13bf5f4bd9f
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Mar 25 17:39:44 2021 +0300

    all: imp some tests
This commit is contained in:
Ainar Garipov 2021-03-25 18:03:29 +03:00
parent 3764c1dfe4
commit 27f4f05273
6 changed files with 42 additions and 40 deletions

View File

@ -104,7 +104,7 @@ func TestAnnotate(t *testing.T) {
require.NotNil(t, errPtr)
err := *errPtr
require.NotNil(t, err)
require.Error(t, err)
assert.Equal(t, wantMsg, err.Error())
})
@ -117,7 +117,7 @@ func TestAnnotate(t *testing.T) {
}
err := f()
require.NotNil(t, err)
require.Error(t, err)
assert.Equal(t, wantMsg, err.Error())
})

View File

@ -13,21 +13,21 @@ import (
func TestLimitReadCloser(t *testing.T) {
testCases := []struct {
want error
name string
n int64
want error
}{{
want: nil,
name: "positive",
n: 1,
want: nil,
}, {
want: nil,
name: "zero",
n: 0,
want: nil,
}, {
want: fmt.Errorf("aghio: invalid n in LimitReadCloser: -1"),
name: "negative",
n: -1,
want: fmt.Errorf("aghio: invalid n in LimitReadCloser: -1"),
}}
for _, tc := range testCases {
@ -40,37 +40,37 @@ func TestLimitReadCloser(t *testing.T) {
func TestLimitedReadCloser_Read(t *testing.T) {
testCases := []struct {
name string
limit int64
rStr string
want int
err error
name string
rStr string
limit int64
want int
}{{
name: "perfectly_match",
limit: 3,
rStr: "abc",
want: 3,
err: nil,
}, {
name: "eof",
limit: 3,
rStr: "",
want: 0,
err: io.EOF,
}, {
name: "limit_reached",
limit: 0,
name: "perfectly_match",
rStr: "abc",
limit: 3,
want: 3,
}, {
err: io.EOF,
name: "eof",
rStr: "",
limit: 3,
want: 0,
}, {
err: &LimitReachedError{
Limit: 0,
},
}, {
name: "truncated",
limit: 2,
name: "limit_reached",
rStr: "abc",
want: 2,
limit: 0,
want: 0,
}, {
err: nil,
name: "truncated",
rStr: "abc",
limit: 2,
want: 2,
}}
for _, tc := range testCases {
@ -79,7 +79,7 @@ func TestLimitedReadCloser_Read(t *testing.T) {
buf := make([]byte, tc.limit+1)
lreader, err := LimitReadCloser(readCloser, tc.limit)
require.Nil(t, err)
require.NoError(t, err)
n, err := lreader.Read(buf)
require.Equal(t, tc.err, err)
@ -90,15 +90,15 @@ func TestLimitedReadCloser_Read(t *testing.T) {
func TestLimitedReadCloser_LimitReachedError(t *testing.T) {
testCases := []struct {
err error
name string
want string
err error
}{{
name: "simplest",
want: "attempted to read more than 0 bytes",
err: &LimitReachedError{
Limit: 0,
},
name: "simplest",
want: "attempted to read more than 0 bytes",
}}
for _, tc := range testCases {

View File

@ -13,7 +13,7 @@ func TestIPDetector_detectSpecialNetwork(t *testing.T) {
var err error
ipd, err = NewIPDetector()
require.Nil(t, err)
require.NoError(t, err)
testCases := []struct {
name string

View File

@ -49,7 +49,8 @@ func TestDHCPCDStaticConfig(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
r := bytes.NewReader(tc.data)
has, err := dhcpcdStaticConfig(r, "wlan0")
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, tc.want, has)
})
}
@ -86,7 +87,8 @@ func TestIfacesStaticConfig(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
r := bytes.NewReader(tc.data)
has, err := ifacesStaticConfig(r, "enp0s3")
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, tc.want, has)
})
}

View File

@ -8,9 +8,9 @@ import (
func TestGetValidNetInterfacesForWeb(t *testing.T) {
ifaces, err := GetValidNetInterfacesForWeb()
require.Nilf(t, err, "Cannot get net interfaces: %s", err)
require.NotEmpty(t, ifaces, "No net interfaces found")
require.NoErrorf(t, err, "cannot get net interfaces: %s", err)
require.NotEmpty(t, ifaces, "no net interfaces found")
for _, iface := range ifaces {
require.NotEmptyf(t, iface.Addresses, "No addresses found for %s", iface.Name)
require.NotEmptyf(t, iface.Addresses, "no addresses found for %s", iface.Name)
}
}

View File

@ -35,10 +35,10 @@ func prepareTestDir(t *testing.T) (dir string) {
t.Helper()
wd, err := os.Getwd()
require.Nil(t, err)
require.NoError(t, err)
dir, err = ioutil.TempDir(wd, "agh-test")
require.Nil(t, err)
require.NoError(t, err)
require.NotEmpty(t, dir)
t.Cleanup(func() {
@ -56,7 +56,7 @@ func prepareTestDir(t *testing.T) (dir string) {
time.Sleep(retryDur)
}
assert.Nil(t, err, "after %s", time.Since(start))
assert.NoError(t, err, "after %s", time.Since(start))
})
return dir