mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-17 02:48:28 -07:00
bfc7e16d84
Closes #2828. Squashed commit of the following: commit 26c6cf81c32469e1c4955aafb40490c29b4d1a99 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Mar 30 17:43:53 2021 +0300 dhcpd: do not assume mac addrs of 6 bytes
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package aghnet
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestValidateHardwareAddress(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
wantErrMsg string
|
|
in net.HardwareAddr
|
|
}{{
|
|
name: "success_eui_48",
|
|
wantErrMsg: "",
|
|
in: net.HardwareAddr{0x00, 0x01, 0x02, 0x03, 0x04, 0x05},
|
|
}, {
|
|
name: "success_eui_64",
|
|
wantErrMsg: "",
|
|
in: net.HardwareAddr{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07},
|
|
}, {
|
|
name: "success_infiniband",
|
|
wantErrMsg: "",
|
|
in: net.HardwareAddr{
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
|
0x10, 0x11, 0x12, 0x13,
|
|
},
|
|
}, {
|
|
name: "error_nil",
|
|
wantErrMsg: `validating hardware address "": address is empty`,
|
|
in: nil,
|
|
}, {
|
|
name: "error_empty",
|
|
wantErrMsg: `validating hardware address "": address is empty`,
|
|
in: net.HardwareAddr{},
|
|
}, {
|
|
name: "error_bad",
|
|
wantErrMsg: `validating hardware address "00:01:02:03": bad len: 4`,
|
|
in: net.HardwareAddr{0x00, 0x01, 0x02, 0x03},
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := ValidateHardwareAddress(tc.in)
|
|
if tc.wantErrMsg == "" {
|
|
assert.NoError(t, err)
|
|
} else {
|
|
require.Error(t, err)
|
|
assert.Equal(t, tc.wantErrMsg, err.Error())
|
|
}
|
|
})
|
|
}
|
|
}
|