mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-28 18:08:51 +03:00
b74b92fc27
Merge in DNS/adguard-home from imp-build-tags to master Squashed commit of the following: commit c15793e04c08097835692568a598b8a8d15f57f4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:25:20 2022 +0300 home: imp build tags commit 2b9b68e9fe6942422951f50d90c70143a3509401 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:23:56 2022 +0300 version: imp build tags commit c0ade3d6ae8885c596fc31312360b25fe992d1e4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:20:48 2022 +0300 dhcpd: imp build tags commit 0ca2a73b7c3b721400a0cc6383cc9e60f4961f22 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:17:22 2022 +0300 aghos: imp build tags commit 733a685b24b56153b96d59cb97c174ad322ff841 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:13:11 2022 +0300 aghnet: imp build tags
126 lines
2.9 KiB
Go
126 lines
2.9 KiB
Go
//go:build linux
|
|
|
|
package aghnet
|
|
|
|
import (
|
|
"io/fs"
|
|
"testing"
|
|
"testing/fstest"
|
|
|
|
"github.com/AdguardTeam/golibs/testutil"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestHasStaticIP(t *testing.T) {
|
|
const ifaceName = "wlan0"
|
|
|
|
const (
|
|
dhcpcd = "etc/dhcpcd.conf"
|
|
netifaces = "etc/network/interfaces"
|
|
)
|
|
|
|
testCases := []struct {
|
|
rootFsys fs.FS
|
|
name string
|
|
wantHas assert.BoolAssertionFunc
|
|
wantErrMsg string
|
|
}{{
|
|
rootFsys: fstest.MapFS{
|
|
dhcpcd: &fstest.MapFile{
|
|
Data: []byte(`#comment` + nl +
|
|
`# comment` + nl +
|
|
`interface eth0` + nl +
|
|
`static ip_address=192.168.0.1/24` + nl +
|
|
`# interface ` + ifaceName + nl +
|
|
`static ip_address=192.168.1.1/24` + nl +
|
|
`# comment` + nl,
|
|
),
|
|
},
|
|
},
|
|
name: "dhcpcd_has_not",
|
|
wantHas: assert.False,
|
|
wantErrMsg: `no information about static ip`,
|
|
}, {
|
|
rootFsys: fstest.MapFS{
|
|
dhcpcd: &fstest.MapFile{
|
|
Data: []byte(`#comment` + nl +
|
|
`# comment` + nl +
|
|
`interface ` + ifaceName + nl +
|
|
`static ip_address=192.168.0.1/24` + nl +
|
|
`# interface ` + ifaceName + nl +
|
|
`static ip_address=192.168.1.1/24` + nl +
|
|
`# comment` + nl,
|
|
),
|
|
},
|
|
},
|
|
name: "dhcpcd_has",
|
|
wantHas: assert.True,
|
|
wantErrMsg: ``,
|
|
}, {
|
|
rootFsys: fstest.MapFS{
|
|
netifaces: &fstest.MapFile{
|
|
Data: []byte(`allow-hotplug ` + ifaceName + nl +
|
|
`#iface enp0s3 inet static` + nl +
|
|
`# address 192.168.0.200` + nl +
|
|
`# netmask 255.255.255.0` + nl +
|
|
`# gateway 192.168.0.1` + nl +
|
|
`iface ` + ifaceName + ` inet dhcp` + nl,
|
|
),
|
|
},
|
|
},
|
|
name: "netifaces_has_not",
|
|
wantHas: assert.False,
|
|
wantErrMsg: `no information about static ip`,
|
|
}, {
|
|
rootFsys: fstest.MapFS{
|
|
netifaces: &fstest.MapFile{
|
|
Data: []byte(`allow-hotplug ` + ifaceName + nl +
|
|
`iface ` + ifaceName + ` inet static` + nl +
|
|
` address 192.168.0.200` + nl +
|
|
` netmask 255.255.255.0` + nl +
|
|
` gateway 192.168.0.1` + nl +
|
|
`#iface ` + ifaceName + ` inet dhcp` + nl,
|
|
),
|
|
},
|
|
},
|
|
name: "netifaces_has",
|
|
wantHas: assert.True,
|
|
wantErrMsg: ``,
|
|
}, {
|
|
rootFsys: fstest.MapFS{
|
|
netifaces: &fstest.MapFile{
|
|
Data: []byte(`source hello` + nl +
|
|
`#iface ` + ifaceName + ` inet static` + nl,
|
|
),
|
|
},
|
|
"hello": &fstest.MapFile{
|
|
Data: []byte(`iface ` + ifaceName + ` inet static` + nl),
|
|
},
|
|
},
|
|
name: "netifaces_another_file",
|
|
wantHas: assert.True,
|
|
wantErrMsg: ``,
|
|
}, {
|
|
rootFsys: fstest.MapFS{
|
|
netifaces: &fstest.MapFile{
|
|
Data: []byte(`source hello` + nl +
|
|
`iface ` + ifaceName + ` inet static` + nl,
|
|
),
|
|
},
|
|
},
|
|
name: "netifaces_ignore_another",
|
|
wantHas: assert.True,
|
|
wantErrMsg: ``,
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
substRootDirFS(t, tc.rootFsys)
|
|
|
|
has, err := IfaceHasStaticIP(ifaceName)
|
|
testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
|
|
|
|
tc.wantHas(t, has)
|
|
})
|
|
}
|
|
}
|