2021-07-30 15:27:24 +03:00
|
|
|
//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) {
|
2021-08-13 19:20:17 +03:00
|
|
|
const iface interfaceName = `em0`
|
2021-07-30 15:27:24 +03:00
|
|
|
const nl = "\n"
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
rcconfData string
|
2021-08-13 19:20:17 +03:00
|
|
|
wantCont bool
|
2021-07-30 15:27:24 +03:00
|
|
|
}{{
|
|
|
|
name: "simple",
|
|
|
|
rcconfData: `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl,
|
2021-08-13 19:20:17 +03:00
|
|
|
wantCont: false,
|
2021-07-30 15:27:24 +03:00
|
|
|
}, {
|
|
|
|
name: "case_insensitiveness",
|
|
|
|
rcconfData: `ifconfig_em0="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl,
|
2021-08-13 19:20:17 +03:00
|
|
|
wantCont: false,
|
2021-07-30 15:27:24 +03:00
|
|
|
}, {
|
|
|
|
name: "comments_and_trash",
|
|
|
|
rcconfData: `# comment 1` + nl +
|
|
|
|
`` + nl +
|
|
|
|
`# comment 2` + nl +
|
|
|
|
`ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl,
|
2021-08-13 19:20:17 +03:00
|
|
|
wantCont: false,
|
2021-07-30 15:27:24 +03:00
|
|
|
}, {
|
|
|
|
name: "aliases",
|
|
|
|
rcconfData: `ifconfig_em0_alias="inet 127.0.0.1/24"` + nl +
|
|
|
|
`ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl,
|
2021-08-13 19:20:17 +03:00
|
|
|
wantCont: false,
|
2021-07-30 15:27:24 +03:00
|
|
|
}, {
|
|
|
|
name: "incorrect_config",
|
|
|
|
rcconfData: `ifconfig_em0="inet6 127.0.0.253 netmask 0xffffffff"` + nl +
|
|
|
|
`ifconfig_em0="inet 256.256.256.256 netmask 0xffffffff"` + nl +
|
|
|
|
`ifconfig_em0=""` + nl,
|
2021-08-13 19:20:17 +03:00
|
|
|
wantCont: true,
|
2021-07-30 15:27:24 +03:00
|
|
|
}}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
r := strings.NewReader(tc.rcconfData)
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2021-08-13 19:20:17 +03:00
|
|
|
_, cont, err := iface.rcConfStaticConfig(r)
|
2021-07-30 15:27:24 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-08-13 19:20:17 +03:00
|
|
|
assert.Equal(t, tc.wantCont, cont)
|
2021-07-30 15:27:24 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|