AdGuardHome/internal/aghnet/net_freebsd_test.go
Eugene Burkov b74b92fc27 Pull request: Improve build tags
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
2022-09-13 20:06:23 +03:00

77 lines
1.8 KiB
Go

//go:build freebsd
package aghnet
import (
"io/fs"
"testing"
"testing/fstest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIfaceHasStaticIP(t *testing.T) {
const (
ifaceName = `em0`
rcConf = "etc/rc.conf"
)
testCases := []struct {
name string
rootFsys fs.FS
wantHas assert.BoolAssertionFunc
}{{
name: "simple",
rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{
Data: []byte(`ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl),
}},
wantHas: assert.True,
}, {
name: "case_insensitiveness",
rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{
Data: []byte(`ifconfig_` + ifaceName + `="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl),
}},
wantHas: assert.True,
}, {
name: "comments_and_trash",
rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{
Data: []byte(`# comment 1` + nl +
`` + nl +
`# comment 2` + nl +
`ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl,
),
}},
wantHas: assert.True,
}, {
name: "aliases",
rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{
Data: []byte(`ifconfig_` + ifaceName + `_alias="inet 127.0.0.1/24"` + nl +
`ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl,
),
}},
wantHas: assert.True,
}, {
name: "incorrect_config",
rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{
Data: []byte(
`ifconfig_` + ifaceName + `="inet6 127.0.0.253 netmask 0xffffffff"` + nl +
`ifconfig_` + ifaceName + `="inet 256.256.256.256 netmask 0xffffffff"` + nl +
`ifconfig_` + ifaceName + `=""` + nl,
),
}},
wantHas: assert.False,
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
substRootDirFS(t, tc.rootFsys)
has, err := IfaceHasStaticIP(ifaceName)
require.NoError(t, err)
tc.wantHas(t, has)
})
}
}