6fa1167251
Merge in DNS/adguard-home from 3289-freebsd-dhcp to master Updates #3289. Squashed commit of the following: commit 1365d8f17293da611b860525d519a7bbd7851902 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Jul 30 15:01:13 2021 +0300 dhcpd: fix doc commit 26724df27e92d457c39c8bf0fb78179a874e3fb2 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Jul 30 14:52:58 2021 +0300 all: imp code & docs commit 9a9574a885d3d2129ef54fefb9a56857ce060cff Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jul 29 15:51:07 2021 +0300 all: fix broadcasting, sup freebsd dhcp, fix http response
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
//go:build freebsd
|
|
// +build freebsd
|
|
|
|
package aghnet
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRcConfStaticConfig(t *testing.T) {
|
|
const ifaceName = `em0`
|
|
const nl = "\n"
|
|
|
|
testCases := []struct {
|
|
name string
|
|
rcconfData string
|
|
wantHas bool
|
|
}{{
|
|
name: "simple",
|
|
rcconfData: `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl,
|
|
wantHas: true,
|
|
}, {
|
|
name: "case_insensitiveness",
|
|
rcconfData: `ifconfig_em0="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl,
|
|
wantHas: true,
|
|
}, {
|
|
name: "comments_and_trash",
|
|
rcconfData: `# comment 1` + nl +
|
|
`` + nl +
|
|
`# comment 2` + nl +
|
|
`ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl,
|
|
wantHas: true,
|
|
}, {
|
|
name: "aliases",
|
|
rcconfData: `ifconfig_em0_alias="inet 127.0.0.1/24"` + nl +
|
|
`ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl,
|
|
wantHas: true,
|
|
}, {
|
|
name: "incorrect_config",
|
|
rcconfData: `ifconfig_em0="inet6 127.0.0.253 netmask 0xffffffff"` + nl +
|
|
`ifconfig_em0="inet 127.0.0.253 net-mask 0xffffffff"` + nl +
|
|
`ifconfig_em0="inet 256.256.256.256 netmask 0xffffffff"` + nl +
|
|
`ifconfig_em0=""` + nl,
|
|
wantHas: false,
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
r := strings.NewReader(tc.rcconfData)
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
has, err := rcConfStaticConfig(r, ifaceName)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, tc.wantHas, has)
|
|
})
|
|
}
|
|
}
|