cherry-pick: 2846 cover aghnet vol.1
Merge in DNS/adguard-home from 2846-cover-aghnet-vol.1 to master Updates #2846. Squashed commit of the following: commit 368e75b0bacb290f9929b8a5a682b06f2d75df6a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Jan 21 19:11:59 2022 +0300 aghnet: imp tests commit 8bb3e2a1680fd30294f7c82693891ffb19474c6a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Jan 21 18:27:06 2022 +0300 aghnet: rm unused test commit 28d8e64880f845810d0af629e5d1f06b9bde5b28 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Jan 21 18:18:22 2022 +0300 aghnet: cover with tests
This commit is contained in:
committed by
Ainar Garipov
parent
4f016b6ed7
commit
2b5927306f
44
internal/aghnet/ipmut_test.go
Normal file
44
internal/aghnet/ipmut_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package aghnet
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/AdguardTeam/golibs/netutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIPMut(t *testing.T) {
|
||||
testIPs := []net.IP{{
|
||||
127, 0, 0, 1,
|
||||
}, {
|
||||
192, 168, 0, 1,
|
||||
}, {
|
||||
8, 8, 8, 8,
|
||||
}}
|
||||
|
||||
t.Run("nil_no_mut", func(t *testing.T) {
|
||||
ipmut := NewIPMut(nil)
|
||||
|
||||
ips := netutil.CloneIPs(testIPs)
|
||||
for i := range ips {
|
||||
ipmut.Load()(ips[i])
|
||||
assert.True(t, ips[i].Equal(testIPs[i]))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("not_nil_mut", func(t *testing.T) {
|
||||
ipmut := NewIPMut(func(ip net.IP) {
|
||||
for i := range ip {
|
||||
ip[i] = 0
|
||||
}
|
||||
})
|
||||
want := netutil.IPv4Zero()
|
||||
|
||||
ips := netutil.CloneIPs(testIPs)
|
||||
for i := range ips {
|
||||
ipmut.Load()(ips[i])
|
||||
assert.True(t, ips[i].Equal(want))
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user