mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-21 12:35:33 +03:00
3f5605c42e
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
44 lines
736 B
Go
44 lines
736 B
Go
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))
|
|
}
|
|
})
|
|
}
|