From 5a801c62183640699f06f2885e81b10eca187e51 Mon Sep 17 00:00:00 2001 From: dhiraj Date: Wed, 7 Apr 2021 15:08:06 +0300 Subject: [PATCH] Coverage Improvements Signed-off-by: dhiraj Change-Id: I1a5208806cf470802bf13b624fbd6af62322e36b --- cmd/vespamgr/config_test.go | 13 ++++ cmd/vespamgr/vespamgr_test.go | 15 +++++ ...nValidMeasurements_xApp_config_test_output.json | 78 ++++++++++++++++++++++ test/noConfig_xApp_config_test_output.json | 78 ++++++++++++++++++++++ test/noMeasurements_xApp_config_test_output.json | 78 ++++++++++++++++++++++ 5 files changed, 262 insertions(+) create mode 100755 test/inValidMeasurements_xApp_config_test_output.json create mode 100755 test/noConfig_xApp_config_test_output.json create mode 100755 test/noMeasurements_xApp_config_test_output.json diff --git a/cmd/vespamgr/config_test.go b/cmd/vespamgr/config_test.go index eacbcbd..d65baa2 100755 --- a/cmd/vespamgr/config_test.go +++ b/cmd/vespamgr/config_test.go @@ -178,6 +178,19 @@ func TestParseXAppDescriptor(t *testing.T) { assert.Equal(t, "App2ExampleCounterOneObjectInstance", appMetrics["App2ExampleCounterOne"].ObjectInstance) assert.Equal(t, "App2ExampleCounterTwoObject", appMetrics["App2ExampleCounterTwo"].ObjectName) assert.Equal(t, "App2ExampleCounterTwoObjectInstance", appMetrics["App2ExampleCounterTwo"].ObjectInstance) + + bytes, err = ioutil.ReadFile("../../test/noConfig_xApp_config_test_output.json") + assert.Nil(t, err) + appMetrics = vespaMgr.ParseMetricsFromDescriptor(bytes, appMetrics) + + bytes, err = ioutil.ReadFile("../../test/noMeasurements_xApp_config_test_output.json") + assert.Nil(t, err) + appMetrics = vespaMgr.ParseMetricsFromDescriptor(bytes, appMetrics) + + bytes, err = ioutil.ReadFile("../../test/inValidMeasurements_xApp_config_test_output.json") + assert.Nil(t, err) + appMetrics = vespaMgr.ParseMetricsFromDescriptor(bytes, appMetrics) + } func TestParseXAppDescriptorWithNoConfig(t *testing.T) { diff --git a/cmd/vespamgr/vespamgr_test.go b/cmd/vespamgr/vespamgr_test.go index 2b84ef5..9a9ca85 100755 --- a/cmd/vespamgr/vespamgr_test.go +++ b/cmd/vespamgr/vespamgr_test.go @@ -163,3 +163,18 @@ func executeRequest(req *http.Request, handleR http.HandlerFunc) *httptest.Respo func TestVespaMgrTestSuite(t *testing.T) { suite.Run(t, new(VespaMgrTestSuite)) } + +func (suite *VespaMgrTestSuite) TestCreateConf() { + suite.vespaMgr.CreateConf("/unknown/text.txt", []byte{}) +} + +func (suite *VespaMgrTestSuite) TestHandleMeasurements() { + data, err := ioutil.ReadFile("../../test/xApp_config_test_output.json") + suite.Nil(err) + + pbodyEn, _ := json.Marshal(data) + req, _ := http.NewRequest("POST", "/ric/v1/measurements", bytes.NewBuffer(pbodyEn)) + handleFunc := http.HandlerFunc(suite.vespaMgr.HandleMeasurements) + response := executeRequest(req, handleFunc) + suite.Equal(http.StatusOK, response.Code) +} diff --git a/test/inValidMeasurements_xApp_config_test_output.json b/test/inValidMeasurements_xApp_config_test_output.json new file mode 100755 index 0000000..8949859 --- /dev/null +++ b/test/inValidMeasurements_xApp_config_test_output.json @@ -0,0 +1,78 @@ +[ + { + "metadata": { }, + "descriptor": { }, + "config": { + "local": { + "host": ":8080" + }, + "logger": { + "level": 5 + }, + "measurements": [ + { + "moId_1": "SEP-12/XAPP-1", + "measType_1": "X2", + "measId_1": "9001", + "measInterval_1": "60", + "metrics_1": [ + { + "name": "App1ExampleCounterOne", + "objectName": "App1ExampleCounterOneObject", + "objectInstance": "App1ExampleCounterOneObjectInstance", + "counterId": "0011", + "type": "counter", + "description": "Example counter 1" + }, + { + "name": "App1ExampleCounterTwo", + "objectName": "App1ExampleCounterTwoObject", + "objectInstance": "App1ExampleCounterTwoObjectInstance", + "counterId": "0012", + "type": "counter", + "description": "Example counter 2" + } + ] + } + ] + } + }, + { + "metadata": {}, + "descriptor": {}, + "config": { + "local": { + "host": ":8080" + }, + "logger": { + "level": 3 + }, + "measurements": [ + { + "moId": "SEP-12/XAPP-2", + "measType": "X2", + "measId": "9002", + "measInterval": "60", + "metrics": [ + { + "name": "App2ExampleCounterOne", + "objectName": "App2ExampleCounterOneObject", + "objectInstance": "App2ExampleCounterOneObjectInstance", + "counterId": "0021", + "type": "counter", + "description": "Example counter 1" + }, + { + "name": "App2ExampleCounterTwo", + "objectName": "App2ExampleCounterTwoObject", + "objectInstance": "App2ExampleCounterTwoObjectInstance", + "counterId": "0022", + "type": "counter", + "description": "Example counter 2" + } + ] + } + ] + } + } +] diff --git a/test/noConfig_xApp_config_test_output.json b/test/noConfig_xApp_config_test_output.json new file mode 100755 index 0000000..8c94811 --- /dev/null +++ b/test/noConfig_xApp_config_test_output.json @@ -0,0 +1,78 @@ +[ + { + "metadata": { }, + "descriptor": { }, + "config_1": { + "local": { + "host": ":8080" + }, + "logger": { + "level": 5 + }, + "measurements": [ + { + "moId": "SEP-12/XAPP-1", + "measType": "X2", + "measId": "9001", + "measInterval": "60", + "metrics": [ + { + "name": "App1ExampleCounterOne", + "objectName": "App1ExampleCounterOneObject", + "objectInstance": "App1ExampleCounterOneObjectInstance", + "counterId": "0011", + "type": "counter", + "description": "Example counter 1" + }, + { + "name": "App1ExampleCounterTwo", + "objectName": "App1ExampleCounterTwoObject", + "objectInstance": "App1ExampleCounterTwoObjectInstance", + "counterId": "0012", + "type": "counter", + "description": "Example counter 2" + } + ] + } + ] + } + }, + { + "metadata": {}, + "descriptor": {}, + "config": { + "local": { + "host": ":8080" + }, + "logger": { + "level": 3 + }, + "measurements": [ + { + "moId": "SEP-12/XAPP-2", + "measType": "X2", + "measId": "9002", + "measInterval": "60", + "metrics": [ + { + "name": "App2ExampleCounterOne", + "objectName": "App2ExampleCounterOneObject", + "objectInstance": "App2ExampleCounterOneObjectInstance", + "counterId": "0021", + "type": "counter", + "description": "Example counter 1" + }, + { + "name": "App2ExampleCounterTwo", + "objectName": "App2ExampleCounterTwoObject", + "objectInstance": "App2ExampleCounterTwoObjectInstance", + "counterId": "0022", + "type": "counter", + "description": "Example counter 2" + } + ] + } + ] + } + } +] diff --git a/test/noMeasurements_xApp_config_test_output.json b/test/noMeasurements_xApp_config_test_output.json new file mode 100755 index 0000000..fa142c3 --- /dev/null +++ b/test/noMeasurements_xApp_config_test_output.json @@ -0,0 +1,78 @@ +[ + { + "metadata": { }, + "descriptor": { }, + "config": { + "local": { + "host": ":8080" + }, + "logger": { + "level": 5 + }, + "measurements_1": [ + { + "moId": "SEP-12/XAPP-1", + "measType": "X2", + "measId": "9001", + "measInterval": "60", + "metrics": [ + { + "name": "App1ExampleCounterOne", + "objectName": "App1ExampleCounterOneObject", + "objectInstance": "App1ExampleCounterOneObjectInstance", + "counterId": "0011", + "type": "counter", + "description": "Example counter 1" + }, + { + "name": "App1ExampleCounterTwo", + "objectName": "App1ExampleCounterTwoObject", + "objectInstance": "App1ExampleCounterTwoObjectInstance", + "counterId": "0012", + "type": "counter", + "description": "Example counter 2" + } + ] + } + ] + } + }, + { + "metadata": {}, + "descriptor": {}, + "config": { + "local": { + "host": ":8080" + }, + "logger": { + "level": 3 + }, + "measurements": [ + { + "moId": "SEP-12/XAPP-2", + "measType": "X2", + "measId": "9002", + "measInterval": "60", + "metrics": [ + { + "name": "App2ExampleCounterOne", + "objectName": "App2ExampleCounterOneObject", + "objectInstance": "App2ExampleCounterOneObjectInstance", + "counterId": "0021", + "type": "counter", + "description": "Example counter 1" + }, + { + "name": "App2ExampleCounterTwo", + "objectName": "App2ExampleCounterTwoObject", + "objectInstance": "App2ExampleCounterTwoObjectInstance", + "counterId": "0022", + "type": "counter", + "description": "Example counter 2" + } + ] + } + ] + } + } +] -- 2.16.6