From 05e22e1a72c59960687c25495e66d532e66ba592 Mon Sep 17 00:00:00 2001 From: Oliver Herms <oliver.herms@exaring.de> Date: Fri, 5 Oct 2018 17:36:37 +0200 Subject: [PATCH] More tests --- protocols/bmp/packet/initiation_message.go | 5 ----- protocols/bmp/packet/initiation_message_test.go | 11 +++++++++++ protocols/bmp/packet/peer_down_test.go | 12 ++++++++++++ protocols/bmp/packet/peer_up_test.go | 11 +++++++++++ protocols/bmp/packet/route_mirroring_test.go | 11 +++++++++++ protocols/bmp/packet/route_monitoring_test.go | 11 +++++++++++ protocols/bmp/packet/stats_report_test.go | 12 ++++++++++++ protocols/bmp/packet/termination_message_test.go | 11 +++++++++++ 8 files changed, 79 insertions(+), 5 deletions(-) diff --git a/protocols/bmp/packet/initiation_message.go b/protocols/bmp/packet/initiation_message.go index 6a3c02f6..076d0f4b 100644 --- a/protocols/bmp/packet/initiation_message.go +++ b/protocols/bmp/packet/initiation_message.go @@ -16,11 +16,6 @@ func (im *InitiationMessage) MsgType() uint8 { return im.CommonHeader.MsgType } -// SetCommonHeader sets the common header -func (im *InitiationMessage) SetCommonHeader(ch *CommonHeader) { - im.CommonHeader = ch -} - func decodeInitiationMessage(buf *bytes.Buffer, ch *CommonHeader) (Msg, error) { im := &InitiationMessage{ TLVs: make([]*InformationTLV, 0, 2), diff --git a/protocols/bmp/packet/initiation_message_test.go b/protocols/bmp/packet/initiation_message_test.go index fdd32737..4513a2be 100644 --- a/protocols/bmp/packet/initiation_message_test.go +++ b/protocols/bmp/packet/initiation_message_test.go @@ -7,6 +7,17 @@ import ( "github.com/stretchr/testify/assert" ) +func TestInitiationMessageMsgType(t *testing.T) { + pd := &InitiationMessage{ + CommonHeader: &CommonHeader{ + MsgType: 100, + }, + } + + if pd.MsgType() != 100 { + t.Errorf("Unexpected result") + } +} func TestDecodeInitiationMessage(t *testing.T) { tests := []struct { name string diff --git a/protocols/bmp/packet/peer_down_test.go b/protocols/bmp/packet/peer_down_test.go index 01d7dac8..61f2e9a6 100644 --- a/protocols/bmp/packet/peer_down_test.go +++ b/protocols/bmp/packet/peer_down_test.go @@ -7,6 +7,18 @@ import ( "github.com/stretchr/testify/assert" ) +func TestPeerDownMsgType(t *testing.T) { + pd := &PeerDownNotification{ + CommonHeader: &CommonHeader{ + MsgType: 100, + }, + } + + if pd.MsgType() != 100 { + t.Errorf("Unexpected result") + } +} + func TestDecodePeerDownNotification(t *testing.T) { tests := []struct { name string diff --git a/protocols/bmp/packet/peer_up_test.go b/protocols/bmp/packet/peer_up_test.go index c3c2c35f..240f38ab 100644 --- a/protocols/bmp/packet/peer_up_test.go +++ b/protocols/bmp/packet/peer_up_test.go @@ -7,6 +7,17 @@ import ( "github.com/stretchr/testify/assert" ) +func TestPeerUpMsgType(t *testing.T) { + pd := &PeerUpNotification{ + CommonHeader: &CommonHeader{ + MsgType: 100, + }, + } + + if pd.MsgType() != 100 { + t.Errorf("Unexpected result") + } +} func TestDecodePeerUp(t *testing.T) { tests := []struct { name string diff --git a/protocols/bmp/packet/route_mirroring_test.go b/protocols/bmp/packet/route_mirroring_test.go index dd885aca..c62799a3 100644 --- a/protocols/bmp/packet/route_mirroring_test.go +++ b/protocols/bmp/packet/route_mirroring_test.go @@ -7,6 +7,17 @@ import ( "github.com/stretchr/testify/assert" ) +func TestRouteMirrorType(t *testing.T) { + pd := &RouteMirroringMsg{ + CommonHeader: &CommonHeader{ + MsgType: 100, + }, + } + + if pd.MsgType() != 100 { + t.Errorf("Unexpected result") + } +} func TestDecodeRouteMirroringMsg(t *testing.T) { tests := []struct { name string diff --git a/protocols/bmp/packet/route_monitoring_test.go b/protocols/bmp/packet/route_monitoring_test.go index c6cee1f7..d2816934 100644 --- a/protocols/bmp/packet/route_monitoring_test.go +++ b/protocols/bmp/packet/route_monitoring_test.go @@ -7,6 +7,17 @@ import ( "github.com/stretchr/testify/assert" ) +func TestRouteMonitoringMsgType(t *testing.T) { + pd := &RouteMonitoringMsg{ + CommonHeader: &CommonHeader{ + MsgType: 100, + }, + } + + if pd.MsgType() != 100 { + t.Errorf("Unexpected result") + } +} func TestDecodeRouteMonitoringMsg(t *testing.T) { tests := []struct { name string diff --git a/protocols/bmp/packet/stats_report_test.go b/protocols/bmp/packet/stats_report_test.go index f3a6329d..2fc47cbb 100644 --- a/protocols/bmp/packet/stats_report_test.go +++ b/protocols/bmp/packet/stats_report_test.go @@ -7,6 +7,18 @@ import ( "github.com/stretchr/testify/assert" ) +func TestStatsReportMsgType(t *testing.T) { + pd := &StatsReport{ + CommonHeader: &CommonHeader{ + MsgType: 100, + }, + } + + if pd.MsgType() != 100 { + t.Errorf("Unexpected result") + } +} + func TestDecodeStatsReport(t *testing.T) { tests := []struct { name string diff --git a/protocols/bmp/packet/termination_message_test.go b/protocols/bmp/packet/termination_message_test.go index 052290bd..412704b8 100644 --- a/protocols/bmp/packet/termination_message_test.go +++ b/protocols/bmp/packet/termination_message_test.go @@ -7,6 +7,17 @@ import ( "github.com/stretchr/testify/assert" ) +func TestTerminationMessageType(t *testing.T) { + pd := &TerminationMessage{ + CommonHeader: &CommonHeader{ + MsgType: 100, + }, + } + + if pd.MsgType() != 100 { + t.Errorf("Unexpected result") + } +} func TestDecodeTerminationMessage(t *testing.T) { tests := []struct { name string -- GitLab