Skip to content

Commit

Permalink
Pull request: all: imp some tests
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from imp-tests to master

Squashed commit of the following:

commit 6171420
Author: Ainar Garipov <[email protected]>
Date:   Thu Mar 25 17:43:36 2021 +0300

    aghnet: imp test msgs

commit ed2880f
Author: Ainar Garipov <[email protected]>
Date:   Thu Mar 25 17:39:44 2021 +0300

    all: imp some tests
  • Loading branch information
ainar-g committed Mar 25, 2021
1 parent 3764c1d commit 27f4f05
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
4 changes: 2 additions & 2 deletions internal/agherr/agherr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
Expand All @@ -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())
})
Expand Down
40 changes: 20 additions & 20 deletions internal/aghio/limitedreadcloser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -40,37 +40,37 @@ func TestLimitReadCloser(t *testing.T) {

func TestLimitedReadCloser_Read(t *testing.T) {
testCases := []struct {
err error
name string
limit int64
rStr string
limit int64
want int
err error
}{{
err: nil,
name: "perfectly_match",
limit: 3,
rStr: "abc",
limit: 3,
want: 3,
err: nil,
}, {
err: io.EOF,
name: "eof",
limit: 3,
rStr: "",
limit: 3,
want: 0,
err: io.EOF,
}, {
name: "limit_reached",
limit: 0,
rStr: "abc",
want: 0,
err: &LimitReachedError{
Limit: 0,
},
name: "limit_reached",
rStr: "abc",
limit: 0,
want: 0,
}, {
err: nil,
name: "truncated",
limit: 2,
rStr: "abc",
limit: 2,
want: 2,
err: nil,
}}

for _, tc := range testCases {
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/aghnet/ipdetector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions internal/aghnet/net_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -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)
})
}
Expand Down
6 changes: 3 additions & 3 deletions internal/aghnet/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions internal/aghtest/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down

0 comments on commit 27f4f05

Please sign in to comment.