2021-08-12 14:33:53 +00:00
|
|
|
//go:build openbsd
|
|
|
|
// +build openbsd
|
|
|
|
|
|
|
|
package aghnet
|
|
|
|
|
|
|
|
import (
|
2022-03-30 12:11:57 +00:00
|
|
|
"fmt"
|
|
|
|
"io/fs"
|
2021-08-12 14:33:53 +00:00
|
|
|
"testing"
|
2022-03-30 12:11:57 +00:00
|
|
|
"testing/fstest"
|
2021-08-12 14:33:53 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-03-30 12:11:57 +00:00
|
|
|
func TestIfaceHasStaticIP(t *testing.T) {
|
|
|
|
const ifaceName = "em0"
|
|
|
|
|
|
|
|
confFile := fmt.Sprintf("etc/hostname.%s", ifaceName)
|
2021-08-12 14:33:53 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
2022-03-30 12:11:57 +00:00
|
|
|
name string
|
|
|
|
rootFsys fs.FS
|
|
|
|
wantHas assert.BoolAssertionFunc
|
2021-08-12 14:33:53 +00:00
|
|
|
}{{
|
2022-03-30 12:11:57 +00:00
|
|
|
name: "simple",
|
|
|
|
rootFsys: fstest.MapFS{
|
|
|
|
confFile: &fstest.MapFile{
|
|
|
|
Data: []byte(`inet 127.0.0.253` + nl),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantHas: assert.True,
|
2021-08-12 14:33:53 +00:00
|
|
|
}, {
|
2022-03-30 12:11:57 +00:00
|
|
|
name: "case_sensitiveness",
|
|
|
|
rootFsys: fstest.MapFS{
|
|
|
|
confFile: &fstest.MapFile{
|
|
|
|
Data: []byte(`InEt 127.0.0.253` + nl),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantHas: assert.False,
|
2021-08-12 14:33:53 +00:00
|
|
|
}, {
|
|
|
|
name: "comments_and_trash",
|
2022-03-30 12:11:57 +00:00
|
|
|
rootFsys: fstest.MapFS{
|
|
|
|
confFile: &fstest.MapFile{
|
|
|
|
Data: []byte(`# comment 1` + nl + nl +
|
|
|
|
`# inet 127.0.0.253` + nl +
|
|
|
|
`inet` + nl,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantHas: assert.False,
|
2021-08-12 14:33:53 +00:00
|
|
|
}, {
|
|
|
|
name: "incorrect_config",
|
2022-03-30 12:11:57 +00:00
|
|
|
rootFsys: fstest.MapFS{
|
|
|
|
confFile: &fstest.MapFile{
|
|
|
|
Data: []byte(`inet6 127.0.0.253` + nl + `inet 256.256.256.256` + nl),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantHas: assert.False,
|
2021-08-12 14:33:53 +00:00
|
|
|
}}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2022-03-30 12:11:57 +00:00
|
|
|
substRootDirFS(t, tc.rootFsys)
|
|
|
|
|
|
|
|
has, err := IfaceHasStaticIP(ifaceName)
|
2021-08-12 14:33:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-30 12:11:57 +00:00
|
|
|
tc.wantHas(t, has)
|
2021-08-12 14:33:53 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|