Pull request 2361: imp-test-file-names
Merge in DNS/adguard-home from imp-test-file-names to master Squashed commit of the following: commit a0827efdf633fba012c5eb0e0f69eaabf7629724 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 10 21:41:46 2025 +0300 all: imp tests commit 21fc274d9276ce0442572261ea39a1c018490870 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 10 19:40:40 2025 +0300 all: imp test file names
This commit is contained in:
71
internal/aghnet/net_openbsd_internal_test.go
Normal file
71
internal/aghnet/net_openbsd_internal_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
//go:build openbsd
|
||||
|
||||
package aghnet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIfaceHasStaticIP(t *testing.T) {
|
||||
const ifaceName = "em0"
|
||||
|
||||
confFile := fmt.Sprintf("etc/hostname.%s", ifaceName)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
rootFsys fs.FS
|
||||
wantHas assert.BoolAssertionFunc
|
||||
}{{
|
||||
name: "simple",
|
||||
rootFsys: fstest.MapFS{
|
||||
confFile: &fstest.MapFile{
|
||||
Data: []byte(`inet 127.0.0.253` + nl),
|
||||
},
|
||||
},
|
||||
wantHas: assert.True,
|
||||
}, {
|
||||
name: "case_sensitiveness",
|
||||
rootFsys: fstest.MapFS{
|
||||
confFile: &fstest.MapFile{
|
||||
Data: []byte(`InEt 127.0.0.253` + nl),
|
||||
},
|
||||
},
|
||||
wantHas: assert.False,
|
||||
}, {
|
||||
name: "comments_and_trash",
|
||||
rootFsys: fstest.MapFS{
|
||||
confFile: &fstest.MapFile{
|
||||
Data: []byte(`# comment 1` + nl + nl +
|
||||
`# inet 127.0.0.253` + nl +
|
||||
`inet` + nl,
|
||||
),
|
||||
},
|
||||
},
|
||||
wantHas: assert.False,
|
||||
}, {
|
||||
name: "incorrect_config",
|
||||
rootFsys: fstest.MapFS{
|
||||
confFile: &fstest.MapFile{
|
||||
Data: []byte(`inet6 127.0.0.253` + nl + `inet 256.256.256.256` + 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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user