Pull request: dhcpd: add ips and text option types
Updates #2385. Squashed commit of the following: commit ce8467f1c013c6b3fef59667084e2c6569a7213c Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Mar 15 19:02:17 2021 +0300 dhcpd: add ips and text option types
This commit is contained in:
@@ -124,67 +124,3 @@ func TestNormalizeLeases(t *testing.T) {
|
||||
assert.Equal(t, leases[1].HWAddr, staticLeases[1].HWAddr)
|
||||
assert.Equal(t, leases[2].HWAddr, dynLeases[1].HWAddr)
|
||||
}
|
||||
|
||||
func TestOptions(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
optStr string
|
||||
wantVal []byte
|
||||
wantCode uint8
|
||||
}{{
|
||||
name: "success_hex",
|
||||
optStr: "12 hex abcdef",
|
||||
wantVal: []byte{0xab, 0xcd, 0xef},
|
||||
wantCode: 12,
|
||||
}, {
|
||||
name: "bad_hex",
|
||||
optStr: "12 hex abcdefx",
|
||||
wantVal: nil,
|
||||
wantCode: 0,
|
||||
}, {
|
||||
name: "success_ip",
|
||||
optStr: "123 ip 1.2.3.4",
|
||||
wantVal: net.IP{1, 2, 3, 4},
|
||||
wantCode: 123,
|
||||
}, {
|
||||
name: "success_ipv6",
|
||||
optStr: "123 ip ::1234",
|
||||
wantVal: net.IP{
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0x12, 0x34,
|
||||
},
|
||||
wantCode: 123,
|
||||
}, {
|
||||
name: "bad_code",
|
||||
optStr: "256 ip 1.1.1.1",
|
||||
wantVal: nil,
|
||||
wantCode: 0,
|
||||
}, {
|
||||
name: "negative_code",
|
||||
optStr: "-1 ip 1.1.1.1",
|
||||
wantVal: nil,
|
||||
wantCode: 0,
|
||||
}, {
|
||||
name: "bad_ip",
|
||||
optStr: "12 ip 1.1.1.1x",
|
||||
wantVal: nil,
|
||||
wantCode: 0,
|
||||
}, {
|
||||
name: "bad_mode",
|
||||
wantVal: nil,
|
||||
optStr: "12 x 1.1.1.1",
|
||||
wantCode: 0,
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
code, val := parseOptionString(tc.optStr)
|
||||
require.Equal(t, tc.wantCode, code)
|
||||
if tc.wantVal != nil {
|
||||
assert.Equal(t, tc.wantVal, val)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user