mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2026-10-21 03:03:08 +00:00
Some checks are pending
build / test (macOS-latest) (push) Waiting to run
build / test (ubuntu-latest) (push) Waiting to run
build / test (windows-latest) (push) Waiting to run
build / build-release (push) Blocked by required conditions
build / notify (push) Blocked by required conditions
lint / go-lint (push) Waiting to run
lint / eslint (push) Waiting to run
lint / notify (push) Blocked by required conditions
Squashed commit of the following:
commit 0e52f80ffc635991b019f402e5cb9ba866dcf128
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Thu Jun 25 10:43:39 2026 +0700
all: upd dnsproxy
commit 61c04a949d908b26c8dff98f3b803d97970c6966
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jun 24 09:24:00 2026 +0700
all: fix gofumpt
commit 4a56a75d69e737925d59b9170242c5149004dfc4
Merge: 8ee75d5be 3a182fec4
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jun 24 09:13:13 2026 +0700
Merge remote-tracking branch 'origin/master' into AGDNS-4107-upd-dnsproxy
# Conflicts:
# go.sum
commit 8ee75d5be61a72d47bb72a7de3b273ae4a30f0fb
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jun 24 09:10:57 2026 +0700
all: upd dnsproxy
commit 8a5b3c4b4463ee5f777891206d8640ec54b85299
Merge: bd4b6aa13 922a7aaf0
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Mon Jun 22 12:40:48 2026 +0700
Merge remote-tracking branch 'origin/master' into AGDNS-4107-upd-dnsproxy
commit bd4b6aa139e78244480ccca04639d828f8d8855c
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Thu Jun 11 15:19:00 2026 +0700
all: upd deps
133 lines
3 KiB
Go
133 lines
3 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)
|
|
|
|
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
|
has, err := IfaceHasStaticIP(ctx, testCmdCons, ifaceName)
|
|
testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
|
|
|
|
tc.wantHas(t, has)
|
|
})
|
|
}
|
|
}
|