From 4e1edd39c2333af217d8972ad8c1b7b0556c93cc Mon Sep 17 00:00:00 2001 From: Hiroshi Yokoi Date: Sun, 15 Feb 2015 11:53:56 +0900 Subject: test: not rely on the type check auto conversion in assert.Equal --- packet/validate_test.go | 30 +++++++++++++++--------------- server/fsm_test.go | 12 ++++++------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packet/validate_test.go b/packet/validate_test.go index 7f5d93ec..effd9d89 100644 --- a/packet/validate_test.go +++ b/packet/validate_test.go @@ -155,8 +155,8 @@ func Test_Validate_duplicate_attribute(t *testing.T) { assert.Equal(false, res) assert.Error(err) e := err.(*MessageError) - assert.Equal(BGP_ERROR_UPDATE_MESSAGE_ERROR, e.TypeCode) - assert.Equal(BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, e.SubTypeCode) + assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode) + assert.Equal(uint8(BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST), e.SubTypeCode) assert.Nil(e.Data) } @@ -168,10 +168,10 @@ func Test_Validate_mandatory_missing(t *testing.T) { assert.Equal(false, res) assert.Error(err) e := err.(*MessageError) - assert.Equal(BGP_ERROR_UPDATE_MESSAGE_ERROR, e.TypeCode) - assert.Equal(BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE, e.SubTypeCode) + assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode) + assert.Equal(uint8(BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE), e.SubTypeCode) missing, _ := binary.Uvarint(e.Data) - assert.Equal(1, missing) + assert.Equal(uint8(1), missing) } func Test_Validate_mandatory_missing_nocheck(t *testing.T) { @@ -198,8 +198,8 @@ func Test_Validate_invalid_origin(t *testing.T) { assert.Equal(false, res) assert.Error(err) e := err.(*MessageError) - assert.Equal(BGP_ERROR_UPDATE_MESSAGE_ERROR, e.TypeCode) - assert.Equal(BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE, e.SubTypeCode) + assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode) + assert.Equal(uint8(BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE), e.SubTypeCode) assert.Equal(originBytes, e.Data) } @@ -219,8 +219,8 @@ func Test_Validate_invalid_nexthop_zero(t *testing.T) { assert.Equal(false, res) assert.Error(err) e := err.(*MessageError) - assert.Equal(BGP_ERROR_UPDATE_MESSAGE_ERROR, e.TypeCode) - assert.Equal(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE, e.SubTypeCode) + assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode) + assert.Equal(uint8(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE), e.SubTypeCode) assert.Equal(nexthopBytes, e.Data) } @@ -240,8 +240,8 @@ func Test_Validate_invalid_nexthop_lo(t *testing.T) { assert.Equal(false, res) assert.Error(err) e := err.(*MessageError) - assert.Equal(BGP_ERROR_UPDATE_MESSAGE_ERROR, e.TypeCode) - assert.Equal(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE, e.SubTypeCode) + assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode) + assert.Equal(uint8(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE), e.SubTypeCode) assert.Equal(nexthopBytes, e.Data) } @@ -261,8 +261,8 @@ func Test_Validate_invalid_nexthop_de(t *testing.T) { assert.Equal(false, res) assert.Error(err) e := err.(*MessageError) - assert.Equal(BGP_ERROR_UPDATE_MESSAGE_ERROR, e.TypeCode) - assert.Equal(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE, e.SubTypeCode) + assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode) + assert.Equal(uint8(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE), e.SubTypeCode) assert.Equal(nexthopBytes, e.Data) } @@ -281,7 +281,7 @@ func Test_Validate_unrecognized_well_known(t *testing.T) { assert.Equal(false, res) assert.Error(err) e := err.(*MessageError) - assert.Equal(BGP_ERROR_UPDATE_MESSAGE_ERROR, e.TypeCode) - assert.Equal(BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE, e.SubTypeCode) + assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode) + assert.Equal(uint8(BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE), e.SubTypeCode) assert.Equal(unknownBytes, e.Data) } diff --git a/server/fsm_test.go b/server/fsm_test.go index 5a1feafa..ae31cc5a 100644 --- a/server/fsm_test.go +++ b/server/fsm_test.go @@ -145,8 +145,8 @@ func TestFSMHandlerOpensent_HoldTimerExpired(t *testing.T) { assert.Equal(bgp.BGP_FSM_IDLE, state) lastMsg := m.sendBuf[len(m.sendBuf)-1] sent, _ := bgp.ParseBGPMessage(lastMsg) - assert.Equal(bgp.BGP_MSG_NOTIFICATION, sent.Header.Type) - assert.Equal(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, sent.Body.(*bgp.BGPNotification).ErrorCode) + assert.Equal(uint8(bgp.BGP_MSG_NOTIFICATION), sent.Header.Type) + assert.Equal(uint8(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED), sent.Body.(*bgp.BGPNotification).ErrorCode) } @@ -169,8 +169,8 @@ func TestFSMHandlerOpenconfirm_HoldTimerExpired(t *testing.T) { assert.Equal(bgp.BGP_FSM_IDLE, state) lastMsg := m.sendBuf[len(m.sendBuf)-1] sent, _ := bgp.ParseBGPMessage(lastMsg) - assert.Equal(bgp.BGP_MSG_NOTIFICATION, sent.Header.Type) - assert.Equal(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, sent.Body.(*bgp.BGPNotification).ErrorCode) + assert.Equal(uint8(bgp.BGP_MSG_NOTIFICATION), sent.Header.Type) + assert.Equal(uint8(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED), sent.Body.(*bgp.BGPNotification).ErrorCode) } @@ -207,8 +207,8 @@ func TestFSMHandlerEstablish_HoldTimerExpired(t *testing.T) { assert.Equal(bgp.BGP_FSM_IDLE, state) lastMsg := m.sendBuf[len(m.sendBuf)-1] sent, _ := bgp.ParseBGPMessage(lastMsg) - assert.Equal(bgp.BGP_MSG_NOTIFICATION, sent.Header.Type) - assert.Equal(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, sent.Body.(*bgp.BGPNotification).ErrorCode) + assert.Equal(uint8(bgp.BGP_MSG_NOTIFICATION), sent.Header.Type) + assert.Equal(uint8(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED), sent.Body.(*bgp.BGPNotification).ErrorCode) } func makePeerAndHandler() (*Peer, *FSMHandler) { -- cgit v1.2.3