-
Notifications
You must be signed in to change notification settings - Fork 0
/
net_openbsd_test.go
71 lines (62 loc) · 1.33 KB
/
net_openbsd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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)
})
}
}