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()) } }) } }