From 97d7cfc9e8eea7ed989e4867a662f96207973ca6 Mon Sep 17 00:00:00 2001 From: Agarwal-Shivansh <117628143+Agarwal-Shivansh@users.noreply.github.com> Date: Sun, 2 Jun 2024 21:10:55 +0530 Subject: [PATCH] Pdubuilder test (#5) * Added GHA for ccc service model * Split the pdubuilder into top level messages and add unit tests * Added encoder and decoder test * Apply suggestions from code review --------- Co-authored-by: gab-arrobo --- .../pdubuilder/cc-action-definition_test.go | 27 +++++++++++++++ .../pdubuilder/ccc-control-header_test.go | 16 +++++++++ .../pdubuilder/ccc-control-message_test.go | 9 +++++ .../pdubuilder/ccc-control-outcome_test.go | 17 ++++++++++ .../ccc-event-trigger-definition_test.go | 33 +++++++++++++++++++ .../pdubuilder/ccc-indication-header_test.go | 19 +++++++++-- .../pdubuilder/ccc-indication-message_test.go | 19 +++++++++++ .../ccc-ranFunction-definition_test.go | 2 ++ 8 files changed, 140 insertions(+), 2 deletions(-) diff --git a/servicemodels/e2sm_ccc/pdubuilder/cc-action-definition_test.go b/servicemodels/e2sm_ccc/pdubuilder/cc-action-definition_test.go index abd65fe8..b2f7ba23 100644 --- a/servicemodels/e2sm_ccc/pdubuilder/cc-action-definition_test.go +++ b/servicemodels/e2sm_ccc/pdubuilder/cc-action-definition_test.go @@ -6,6 +6,7 @@ package pdubuilder import ( "testing" + encoder "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/encoder" e2smcccv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-ccc-ies" e2smcommoniesv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-common-ies" "github.com/stretchr/testify/assert" @@ -14,6 +15,21 @@ import ( func TestCreateE2SmCCcRIcactionDefinition(t *testing.T) { ricStyleType := &e2smcommoniesv1.RicStyleType{} actionDefinitionFormat := &e2smcccv1.ActionDefinitionFormat{} + + result, err := CreateE2SmCCcRIcactionDefinition(ricStyleType, actionDefinitionFormat) + + encodedMsg, err := encoder.PerEncodeE2SmCCcRIcactionDefinition(result) + assert.NoError(t, err) + assert.NotNil(t, encodedMsg) + decodedMsg, err := encoder.PerDecodeE2SmCCcRIcactionDefinition(encodedMsg) + assert.NoError(t, err) + assert.NotNil(t, decodedMsg) + assert.Equal(t, result, decodedMsg) + assert.NoError(t, err) + assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) + result, err := CreateE2SmCCcRIcactionDefinition(ricStyleType, actionDefinitionFormat) assert.NoError(t, err) assert.NotNil(t, result) @@ -30,6 +46,11 @@ func TestCreateListOfRanconfigurationStructuresForAdf(t *testing.T) { result, err := CreateListOfRanconfigurationStructuresForAdf(value) assert.NoError(t, err) assert.NotNil(t, result) + + for _, item := range result.Value { + err = item.Validate() + assert.NoError(t, err) + } } func TestCreateE2SmCCcActionDefinitionFormat1(t *testing.T) { @@ -46,6 +67,9 @@ func TestCreateE2SmCCcActionDefinitionFormat1(t *testing.T) { result, err := CreateE2SmCCcActionDefinitionFormat1(listOfNodeLevelRanconfigurationStructuresForAdf) assert.NoError(t, err) assert.NotNil(t, result) + + err = result.Validate() + assert.NoError(t, err) } func TestCreateE2SmCCcActionDefinitionFormat2(t *testing.T) { @@ -61,4 +85,7 @@ func TestCreateE2SmCCcActionDefinitionFormat2(t *testing.T) { result, err := CreateE2SmCCcActionDefinitionFormat2(listOfCellConfigurationsToBeReportedForAdf) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) + } diff --git a/servicemodels/e2sm_ccc/pdubuilder/ccc-control-header_test.go b/servicemodels/e2sm_ccc/pdubuilder/ccc-control-header_test.go index 1cb6a133..9c7091e2 100644 --- a/servicemodels/e2sm_ccc/pdubuilder/ccc-control-header_test.go +++ b/servicemodels/e2sm_ccc/pdubuilder/ccc-control-header_test.go @@ -6,6 +6,7 @@ package pdubuilder import ( "testing" + encoder "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/encoder" e2smcccv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-ccc-ies" e2smcommoniesv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-common-ies" "github.com/stretchr/testify/assert" @@ -17,6 +18,17 @@ func TestCreateE2SmCCcRIcControlHeader(t *testing.T) { result, err := CreateE2SmCCcRIcControlHeader(controlHeaderFormat) assert.NoError(t, err) assert.NotNil(t, result) + + encodedMsg, err := encoder.PerEncodeE2SmCCcRIcControlHeader(result) + assert.NoError(t, err) + assert.NotNil(t, encodedMsg) + decodedMsg, err := encoder.PerDecodeE2SmCCcRIcControlHeader(encodedMsg) + assert.NoError(t, err) + assert.NotNil(t, decodedMsg) + assert.Equal(t, result, decodedMsg) + err = result.Validate() + assert.NoError(t, err) + } func TestCreateE2SmCCcControlHeaderFormat1(t *testing.T) { @@ -24,4 +36,8 @@ func TestCreateE2SmCCcControlHeaderFormat1(t *testing.T) { result, err := CreateE2SmCCcControlHeaderFormat1(ricStyleType) assert.NoError(t, err) assert.NotNil(t, result) + + err = result.Validate() + assert.NoError(t, err) + } diff --git a/servicemodels/e2sm_ccc/pdubuilder/ccc-control-message_test.go b/servicemodels/e2sm_ccc/pdubuilder/ccc-control-message_test.go index 4949b712..d1e12beb 100644 --- a/servicemodels/e2sm_ccc/pdubuilder/ccc-control-message_test.go +++ b/servicemodels/e2sm_ccc/pdubuilder/ccc-control-message_test.go @@ -6,6 +6,7 @@ package pdubuilder import ( "testing" + encoder "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/encoder" e2smcccv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-ccc-ies" "github.com/stretchr/testify/assert" ) @@ -15,6 +16,14 @@ func TestCreateE2SmCCcRIcControlMessage(t *testing.T) { result, err := CreateE2SmCCcRIcControlMessage(controlMessageFormat) assert.NoError(t, err) assert.NotNil(t, result) + + encodedMsg, err := encoder.PerEncodeE2SmCCcRIcControlMessage(result) + assert.NoError(t, err) + assert.NotNil(t, encodedMsg) + decodedMsg, err := encoder.PerDecodeE2SmCCcRIcControlMessage(encodedMsg) + assert.NoError(t, err) + assert.NotNil(t, decodedMsg) + } func TestCreateE2SmCCcControlMessageFormat1(t *testing.T) { diff --git a/servicemodels/e2sm_ccc/pdubuilder/ccc-control-outcome_test.go b/servicemodels/e2sm_ccc/pdubuilder/ccc-control-outcome_test.go index f7051066..c6182dbb 100644 --- a/servicemodels/e2sm_ccc/pdubuilder/ccc-control-outcome_test.go +++ b/servicemodels/e2sm_ccc/pdubuilder/ccc-control-outcome_test.go @@ -6,6 +6,7 @@ package pdubuilder import ( "testing" + encoder "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/encoder" e2smcccv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-ccc-ies" "github.com/stretchr/testify/assert" ) @@ -13,6 +14,18 @@ import ( func TestCreateE2SmCCcRIcControlOutcome(t *testing.T) { controlOutcomeFormat := &e2smcccv1.ControlOutcomeFormat{} result, err := CreateE2SmCCcRIcControlOutcome(controlOutcomeFormat) + + encodedMsg, err := encoder.PerEncodeE2SmCCcRIcControlOutcome(result) + assert.NoError(t, err) + assert.NotNil(t, encodedMsg) + decodedMsg, err := encoder.PerDecodeE2SmCCcRIcControlOutcome(encodedMsg) + assert.NoError(t, err) + assert.NotNil(t, decodedMsg) + assert.Equal(t, result, decodedMsg) + assert.NoError(t, err) + assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) assert.NoError(t, err) assert.NotNil(t, result) } @@ -22,6 +35,8 @@ func TestCreateControlOutcomeFormatE2SmCccControlOutcomeFormat1(t *testing.T) { result, err := CreateControlOutcomeFormatE2SmCccControlOutcomeFormat1(e2SmCccControlOutcomeFormat1) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } func TestCreateControlOutcomeFormatE2SmCccControlOutcomeFormat2(t *testing.T) { @@ -29,4 +44,6 @@ func TestCreateControlOutcomeFormatE2SmCccControlOutcomeFormat2(t *testing.T) { result, err := CreateControlOutcomeFormatE2SmCccControlOutcomeFormat2(e2SmCccControlOutcomeFormat2) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } diff --git a/servicemodels/e2sm_ccc/pdubuilder/ccc-event-trigger-definition_test.go b/servicemodels/e2sm_ccc/pdubuilder/ccc-event-trigger-definition_test.go index 2b4d48db..a1ac9c76 100644 --- a/servicemodels/e2sm_ccc/pdubuilder/ccc-event-trigger-definition_test.go +++ b/servicemodels/e2sm_ccc/pdubuilder/ccc-event-trigger-definition_test.go @@ -6,6 +6,7 @@ package pdubuilder import ( "testing" + encoder "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/encoder" e2smcccv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-ccc-ies" "github.com/stretchr/testify/assert" ) @@ -13,6 +14,18 @@ import ( func TestCreateE2SmCCcRIceventTriggerDefinition(t *testing.T) { eventTriggerDefinitionFormat := &e2smcccv1.EventTriggerDefinitionFormat{} result, err := CreateE2SmCCcRIceventTriggerDefinition(eventTriggerDefinitionFormat) + + encodedMsg, err := encoder.PerEncodeE2SmCCcRIceventTriggerDefinition(result) + assert.NoError(t, err) + assert.NotNil(t, encodedMsg) + decodedMsg, err := encoder.PerDecodeE2SmCCcRIceventTriggerDefinition(encodedMsg) + assert.NoError(t, err) + assert.NotNil(t, decodedMsg) + assert.Equal(t, result, decodedMsg) + assert.NoError(t, err) + assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) assert.NoError(t, err) assert.NotNil(t, result) } @@ -28,6 +41,9 @@ func TestCreateE2SmCCcEventTriggerDefinitionFormat1(t *testing.T) { result, err := CreateE2SmCCcEventTriggerDefinitionFormat1(listOfNodeLevelConfigurationStructuresForEventTrigger) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) + } func TestCreateListOfRanconfigurationStructuresForEventTrigger(t *testing.T) { @@ -38,6 +54,9 @@ func TestCreateListOfRanconfigurationStructuresForEventTrigger(t *testing.T) { result, err := CreateListOfRanconfigurationStructuresForEventTrigger(value) assert.NoError(t, err) assert.NotNil(t, result) + + err = result.Validate() + assert.NoError(t, err) } func TestCreateRanConfigurationStructureName(t *testing.T) { @@ -45,6 +64,8 @@ func TestCreateRanConfigurationStructureName(t *testing.T) { result, err := CreateRanConfigurationStructureName(value) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } func TestCreateListOfAttributes(t *testing.T) { @@ -52,6 +73,8 @@ func TestCreateListOfAttributes(t *testing.T) { result, err := CreateListOfAttributes(value) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } func TestCreateAttributeName(t *testing.T) { @@ -59,6 +82,8 @@ func TestCreateAttributeName(t *testing.T) { result, err := CreateAttributeName(value) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } func TestCreateE2SmCCcEventTriggerDefinitionFormat3(t *testing.T) { @@ -66,6 +91,8 @@ func TestCreateE2SmCCcEventTriggerDefinitionFormat3(t *testing.T) { result, err := CreateE2SmCCcEventTriggerDefinitionFormat3(period) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } func TestCreateEventTriggerDefinitionFormatE2SmCccEventTriggerDefinitionFormat1(t *testing.T) { @@ -73,6 +100,8 @@ func TestCreateEventTriggerDefinitionFormatE2SmCccEventTriggerDefinitionFormat1( result, err := CreateEventTriggerDefinitionFormatE2SmCccEventTriggerDefinitionFormat1(e2SmCccEventTriggerDefinitionFormat1) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } func TestCreateEventTriggerDefinitionFormatE2SmCccEventTriggerDefinitionFormat2(t *testing.T) { @@ -80,6 +109,8 @@ func TestCreateEventTriggerDefinitionFormatE2SmCccEventTriggerDefinitionFormat2( result, err := CreateEventTriggerDefinitionFormatE2SmCccEventTriggerDefinitionFormat2(e2SmCccEventTriggerDefinitionFormat2) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } func TestCreateEventTriggerDefinitionFormatE2SmCccEventTriggerDefinitionFormat3(t *testing.T) { @@ -88,4 +119,6 @@ func TestCreateEventTriggerDefinitionFormatE2SmCccEventTriggerDefinitionFormat3( result, err := CreateEventTriggerDefinitionFormatE2SmCccEventTriggerDefinitionFormat3(e2SmCccEventTriggerDefinitionFormat3) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } diff --git a/servicemodels/e2sm_ccc/pdubuilder/ccc-indication-header_test.go b/servicemodels/e2sm_ccc/pdubuilder/ccc-indication-header_test.go index 0d51f2bc..dda09ee5 100644 --- a/servicemodels/e2sm_ccc/pdubuilder/ccc-indication-header_test.go +++ b/servicemodels/e2sm_ccc/pdubuilder/ccc-indication-header_test.go @@ -4,16 +4,28 @@ package pdubuilder import ( - e2smcccv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-ccc-ies" + encoder "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/encoder" + e2smcccv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-ccc-ies" + e2smcccv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-ccc-ies" "testing" - "github.com/stretchr/testify/assert" ) func TestCreateE2SmCCcRIcIndicationHeader(t *testing.T) { indicationHeaderFormat := &e2smcccv1.IndicationHeaderFormat{} result, err := CreateE2SmCCcRIcIndicationHeader(indicationHeaderFormat) + encodedMsg, err := encoder.PerEncodeE2SmCCcRIcIndicationHeader(result) + assert.NoError(t, err) + assert.NotNil(t, encodedMsg) + decodedMsg, err := encoder.PerDecodeE2SmCCcRIcIndicationHeader(encodedMsg) + assert.NoError(t, err) + assert.NotNil(t, decodedMsg) + assert.Equal(t, result, decodedMsg) + assert.NoError(t, err) + assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) assert.NoError(t, err) assert.NotNil(t, result) } @@ -24,4 +36,7 @@ func TestCreateE2SmCCcIndicationHeaderFormat1(t *testing.T) { result, err := CreateE2SmCCcIndicationHeaderFormat1(indicationReason, eventTime) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) + } diff --git a/servicemodels/e2sm_ccc/pdubuilder/ccc-indication-message_test.go b/servicemodels/e2sm_ccc/pdubuilder/ccc-indication-message_test.go index 1321af1c..b943b355 100644 --- a/servicemodels/e2sm_ccc/pdubuilder/ccc-indication-message_test.go +++ b/servicemodels/e2sm_ccc/pdubuilder/ccc-indication-message_test.go @@ -5,6 +5,7 @@ package pdubuilder import ( "testing" + encoder "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/encoder" e2smcccv1 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_ccc/v1/e2sm-ccc-ies" "github.com/stretchr/testify/assert" @@ -13,6 +14,18 @@ import ( func TestCreateE2SmCCcRIcIndicationMessage(t *testing.T) { indicationMessageFormat := &e2smcccv1.IndicationMessageFormat{} result, err := CreateE2SmCCcRIcIndicationMessage(indicationMessageFormat) + + encodedMsg, err := encoder.PerEncodeE2SmCCcRIcIndicationMessage(result) + assert.NoError(t, err) + assert.NotNil(t, encodedMsg) + decodedMsg, err := encoder.PerDecodeE2SmCCcRIcIndicationMessage(encodedMsg) + assert.NoError(t, err) + assert.NotNil(t, decodedMsg) + assert.Equal(t, result, decodedMsg) + assert.NoError(t, err) + assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) assert.NoError(t, err) assert.NotNil(t, result) } @@ -25,6 +38,8 @@ func TestCreateE2SmCCcIndicationMessageFormat1(t *testing.T) { result, err := CreateE2SmCCcIndicationMessageFormat1(listOfConfigurationStructuresReported) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } func TestCreateListOfConfigurationsReported(t *testing.T) { @@ -32,6 +47,8 @@ func TestCreateListOfConfigurationsReported(t *testing.T) { result, err := CreateListOfConfigurationsReported(value) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } func TestCreateE2SmCCcIndicationMessageFormat2(t *testing.T) { @@ -42,4 +59,6 @@ func TestCreateE2SmCCcIndicationMessageFormat2(t *testing.T) { result, err := CreateE2SmCCcIndicationMessageFormat2(listOfCellsReported) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) } diff --git a/servicemodels/e2sm_ccc/pdubuilder/ccc-ranFunction-definition_test.go b/servicemodels/e2sm_ccc/pdubuilder/ccc-ranFunction-definition_test.go index bfc76dc8..ee298f7f 100644 --- a/servicemodels/e2sm_ccc/pdubuilder/ccc-ranFunction-definition_test.go +++ b/servicemodels/e2sm_ccc/pdubuilder/ccc-ranFunction-definition_test.go @@ -15,4 +15,6 @@ func TestCreateListOfCellsForRanfunctionDefinition(t *testing.T) { result, err := CreateListOfCellsForRanfunctionDefinition(value) assert.NoError(t, err) assert.NotNil(t, result) + err = result.Validate() + assert.NoError(t, err) }