Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 AT&T Intellectual Property. |
| 3 | * Copyright (c) 2018-2019 Nokia. |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Roni Riska | 6ffba08 | 2019-11-27 10:59:54 +0200 | [diff] [blame] | 16 | * |
| 17 | * This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 18 | * platform project (RICP). |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 19 | */ |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 20 | package main |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 21 | |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 22 | import ( |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 23 | "bytes" |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 24 | "encoding/json" |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 25 | "io/ioutil" |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 26 | "os" |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 27 | "testing" |
| 28 | "time" |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 29 | |
| 30 | "github.com/stretchr/testify/assert" |
| 31 | "gopkg.in/yaml.v2" |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 32 | ) |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 33 | |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 34 | func testBaseConf(t *testing.T, vesconf VESAgentConfiguration) { |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 35 | assert.Equal(t, "/tmp/data", vesconf.DataDir) |
| 36 | assert.False(t, vesconf.Debug) |
| 37 | assert.Equal(t, vesconf.Event.MaxMissed, 2) |
| 38 | assert.Equal(t, vesconf.Event.RetryInterval, time.Second*5) |
| 39 | assert.Equal(t, vesconf.Measurement.Prometheus.KeepAlive, time.Second*30) |
Katri Turunen | 3e79fbe | 2019-09-26 12:46:07 +0300 | [diff] [blame] | 40 | assert.Equal(t, vesconf.Event.VNFName, defaultVNFName) |
Roni Riska | 364295f | 2019-09-30 09:39:12 +0300 | [diff] [blame] | 41 | assert.Equal(t, vesconf.Event.NfNamingCode, defaultNFNamingCode) |
Katri Turunen | 3e79fbe | 2019-09-26 12:46:07 +0300 | [diff] [blame] | 42 | assert.Equal(t, vesconf.Event.ReportingEntityName, "Vespa") |
| 43 | // depending on the credentials with which this test is run, |
| 44 | // root or non-root, the code either reads the UUID from the file or |
| 45 | // ends up using the default id. Just check the length here, |
| 46 | // not the actual value. |
| 47 | assert.Len(t, vesconf.Event.ReportingEntityID, len(defaultReportingEntityID)) |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 48 | } |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 49 | |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 50 | func TestBasicConfigContainsCorrectValues(t *testing.T) { |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 51 | vesconf := basicVespaConf() |
| 52 | testBaseConf(t, vesconf) |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 53 | } |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 54 | |
Katri Turunen | 3e79fbe | 2019-09-26 12:46:07 +0300 | [diff] [blame] | 55 | func TestBasicConfigContainsCorrectVNFName(t *testing.T) { |
| 56 | os.Setenv("VESMGR_VNFNAME", "VNF-111") |
Roni Riska | 364295f | 2019-09-30 09:39:12 +0300 | [diff] [blame] | 57 | os.Setenv("VESMGR_NFNAMINGCODE", "code55") |
Katri Turunen | 3e79fbe | 2019-09-26 12:46:07 +0300 | [diff] [blame] | 58 | vesconf := basicVespaConf() |
| 59 | assert.Equal(t, vesconf.Event.VNFName, "VNF-111") |
Roni Riska | 364295f | 2019-09-30 09:39:12 +0300 | [diff] [blame] | 60 | assert.Equal(t, vesconf.Event.NfNamingCode, "code55") |
Katri Turunen | 3e79fbe | 2019-09-26 12:46:07 +0300 | [diff] [blame] | 61 | os.Unsetenv("VESMGR_VNFNAME") |
Roni Riska | 364295f | 2019-09-30 09:39:12 +0300 | [diff] [blame] | 62 | os.Unsetenv("VESMGR_NFNAMINGCODE") |
Katri Turunen | 3e79fbe | 2019-09-26 12:46:07 +0300 | [diff] [blame] | 63 | } |
| 64 | |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 65 | func TestCollectorConfiguration(t *testing.T) { |
Katri Turunen | 3e79fbe | 2019-09-26 12:46:07 +0300 | [diff] [blame] | 66 | os.Unsetenv("VESMGR_VNFNAME") |
Roni Riska | 364295f | 2019-09-30 09:39:12 +0300 | [diff] [blame] | 67 | os.Unsetenv("VESMGR_NFNAMINGCODE") |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 68 | os.Setenv("VESMGR_PRICOLLECTOR_USER", "user123") |
| 69 | os.Setenv("VESMGR_PRICOLLECTOR_PASSWORD", "pass123") |
| 70 | os.Setenv("VESMGR_PRICOLLECTOR_PASSPHRASE", "phrase123") |
| 71 | os.Setenv("VESMGR_PRICOLLECTOR_ADDR", "1.2.3.4") |
| 72 | os.Setenv("VESMGR_PRICOLLECTOR_PORT", "1234") |
| 73 | os.Setenv("VESMGR_PRICOLLECTOR_SERVERROOT", "vescollector") |
| 74 | os.Setenv("VESMGR_PRICOLLECTOR_TOPIC", "sometopic") |
| 75 | os.Setenv("VESMGR_PRICOLLECTOR_SECURE", "true") |
| 76 | |
| 77 | vesconf := basicVespaConf() |
| 78 | getCollectorConfiguration(&vesconf) |
| 79 | |
| 80 | assert.Equal(t, "user123", vesconf.PrimaryCollector.User) |
| 81 | assert.Equal(t, "pass123", vesconf.PrimaryCollector.Password) |
| 82 | assert.Equal(t, "phrase123", vesconf.PrimaryCollector.PassPhrase) |
| 83 | assert.Equal(t, "1.2.3.4", vesconf.PrimaryCollector.FQDN) |
| 84 | assert.Equal(t, 1234, vesconf.PrimaryCollector.Port) |
| 85 | assert.Equal(t, "vescollector", vesconf.PrimaryCollector.ServerRoot) |
| 86 | assert.Equal(t, "sometopic", vesconf.PrimaryCollector.Topic) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 87 | assert.True(t, vesconf.PrimaryCollector.Secure) |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | func TestCollectorConfigurationWhenEnvironmentVariablesAreNotDefined(t *testing.T) { |
Katri Turunen | 3e79fbe | 2019-09-26 12:46:07 +0300 | [diff] [blame] | 91 | os.Unsetenv("VESMGR_VNFNAME") |
Roni Riska | 364295f | 2019-09-30 09:39:12 +0300 | [diff] [blame] | 92 | os.Unsetenv("VESMGR_NFNAMINGCODE") |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 93 | os.Unsetenv("VESMGR_PRICOLLECTOR_USER") |
| 94 | os.Unsetenv("VESMGR_PRICOLLECTOR_PASSWORD") |
| 95 | os.Unsetenv("VESMGR_PRICOLLECTOR_PASSPHRASE") |
| 96 | os.Unsetenv("VESMGR_PRICOLLECTOR_ADDR") |
| 97 | os.Unsetenv("VESMGR_PRICOLLECTOR_PORT") |
| 98 | os.Unsetenv("VESMGR_PRICOLLECTOR_SERVERROOT") |
| 99 | os.Unsetenv("VESMGR_PRICOLLECTOR_TOPIC") |
| 100 | os.Unsetenv("VESMGR_PRICOLLECTOR_SECURE") |
| 101 | |
| 102 | vesconf := basicVespaConf() |
| 103 | getCollectorConfiguration(&vesconf) |
| 104 | |
| 105 | assert.Equal(t, "", vesconf.PrimaryCollector.User) |
| 106 | assert.Equal(t, "", vesconf.PrimaryCollector.Password) |
| 107 | assert.Equal(t, "", vesconf.PrimaryCollector.PassPhrase) |
| 108 | assert.Equal(t, "", vesconf.PrimaryCollector.FQDN) |
| 109 | assert.Equal(t, 8443, vesconf.PrimaryCollector.Port) |
| 110 | assert.Equal(t, "", vesconf.PrimaryCollector.ServerRoot) |
| 111 | assert.Equal(t, "", vesconf.PrimaryCollector.Topic) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 112 | assert.False(t, vesconf.PrimaryCollector.Secure) |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | func TestCollectorConfigurationWhenPrimaryCollectorPortIsNotInteger(t *testing.T) { |
| 116 | os.Setenv("VESMGR_PRICOLLECTOR_PORT", "abcd") |
| 117 | vesconf := basicVespaConf() |
| 118 | getCollectorConfiguration(&vesconf) |
| 119 | assert.Equal(t, 0, vesconf.PrimaryCollector.Port) |
| 120 | } |
| 121 | |
| 122 | func TestCollectorConfigurationWhenPrimaryCollectorSecureIsNotTrueOrFalse(t *testing.T) { |
| 123 | os.Setenv("VESMGR_PRICOLLECTOR_SECURE", "foo") |
| 124 | vesconf := basicVespaConf() |
| 125 | getCollectorConfiguration(&vesconf) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 126 | assert.False(t, vesconf.PrimaryCollector.Secure) |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 127 | } |
| 128 | |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 129 | func TestYamlGenerationWithoutXAppsConfig(t *testing.T) { |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 130 | buffer := new(bytes.Buffer) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 131 | createVespaConfig(buffer, []byte{}) |
Katri Turunen | 4b74f01 | 2019-08-15 10:49:36 +0300 | [diff] [blame] | 132 | var vesconf VESAgentConfiguration |
| 133 | err := yaml.Unmarshal(buffer.Bytes(), &vesconf) |
| 134 | assert.Nil(t, err) |
| 135 | testBaseConf(t, vesconf) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 136 | assert.Empty(t, vesconf.Measurement.Prometheus.Rules.Metrics) |
| 137 | } |
| 138 | |
| 139 | func TestYamlGenerationWithXAppsConfig(t *testing.T) { |
| 140 | buffer := new(bytes.Buffer) |
| 141 | bytes, err := ioutil.ReadFile("../../test/xApp_config_test_output.json") |
| 142 | assert.Nil(t, err) |
| 143 | createVespaConfig(buffer, bytes) |
| 144 | var vesconf VESAgentConfiguration |
| 145 | err = yaml.Unmarshal(buffer.Bytes(), &vesconf) |
| 146 | assert.Nil(t, err) |
| 147 | testBaseConf(t, vesconf) |
| 148 | assert.Len(t, vesconf.Measurement.Prometheus.Rules.Metrics, 4) |
| 149 | } |
| 150 | |
| 151 | // Helper function for the metrics parsing tests |
| 152 | func metricsStringToInterfaceArray(metrics string) []interface{} { |
| 153 | var metricsArray map[string][]interface{} |
| 154 | json.Unmarshal([]byte(metrics), &metricsArray) |
| 155 | return metricsArray["metrics"] |
| 156 | } |
| 157 | |
| 158 | func TestParseMetricsRules(t *testing.T) { |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 159 | metricsJSON := `{"metrics": [ |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 160 | { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }, |
| 161 | { "name": "ricxapp_RMR_ReceiveError", "objectName": "ricxappRMRReceiveErrorCounter", "objectInstance": "ricxappRMRReceiveError" }, |
| 162 | { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted" }, |
| 163 | { "name": "ricxapp_RMR_TransmitError", "objectName": "ricxappRMRTransmitErrorCounter", "objectInstance": "ricxappRMRTransmitError" }, |
| 164 | { "name": "ricxapp_SDL_Stored", "objectName": "ricxappSDLStoredCounter", "objectInstance": "ricxappSDLStored" }, |
| 165 | { "name": "ricxapp_SDL_StoreError", "objectName": "ricxappSDLStoreErrorCounter", "objectInstance": "ricxappSDLStoreError" } ]}` |
| 166 | appMetrics := make(AppMetrics) |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 167 | m := metricsStringToInterfaceArray(metricsJSON) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 168 | appMetrics = parseMetricsRules(m, appMetrics) |
| 169 | assert.Len(t, appMetrics, 6) |
| 170 | assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) |
| 171 | assert.Equal(t, "ricxappRMRTransmitErrorCounter", appMetrics["ricxapp_RMR_TransmitError"].ObjectName) |
| 172 | assert.Equal(t, "ricxappSDLStoreError", appMetrics["ricxapp_SDL_StoreError"].ObjectInstance) |
| 173 | } |
| 174 | |
| 175 | func TestParseMetricsRulesNoMetrics(t *testing.T) { |
| 176 | appMetrics := make(AppMetrics) |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 177 | metricsJSON := `{"metrics": []` |
| 178 | m := metricsStringToInterfaceArray(metricsJSON) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 179 | appMetrics = parseMetricsRules(m, appMetrics) |
| 180 | assert.Empty(t, appMetrics) |
| 181 | } |
| 182 | |
| 183 | func TestParseMetricsRulesAdditionalFields(t *testing.T) { |
| 184 | appMetrics := make(AppMetrics) |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 185 | metricsJSON := `{"metrics": [ |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 186 | { "additionalField": "valueIgnored", "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }]}` |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 187 | m := metricsStringToInterfaceArray(metricsJSON) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 188 | appMetrics = parseMetricsRules(m, appMetrics) |
| 189 | assert.Len(t, appMetrics, 1) |
| 190 | assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) |
| 191 | assert.Equal(t, "ricxappRMRReceived", appMetrics["ricxapp_RMR_Received"].ObjectInstance) |
| 192 | } |
| 193 | |
| 194 | func TestParseMetricsRulesMissingFields(t *testing.T) { |
| 195 | appMetrics := make(AppMetrics) |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 196 | metricsJSON := `{"metrics": [ |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 197 | { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }, |
| 198 | { "name": "ricxapp_RMR_ReceiveError", "objectInstance": "ricxappRMRReceiveError" }, |
| 199 | { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted" }]}` |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 200 | m := metricsStringToInterfaceArray(metricsJSON) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 201 | appMetrics = parseMetricsRules(m, appMetrics) |
| 202 | assert.Len(t, appMetrics, 2) |
| 203 | assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) |
| 204 | assert.Equal(t, "ricxappRMRTransmittedCounter", appMetrics["ricxapp_RMR_Transmitted"].ObjectName) |
| 205 | _, ok := appMetrics["ricxapp_RMR_ReceiveError"] |
| 206 | assert.False(t, ok) |
| 207 | } |
| 208 | |
| 209 | func TestParseMetricsRulesDuplicateDefinitionIsIgnored(t *testing.T) { |
| 210 | appMetrics := make(AppMetrics) |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 211 | metricsJSON := `{"metrics": [ |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 212 | { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }, |
| 213 | { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounterXXX", "objectInstance": "ricxappRMRReceivedXXX" }, |
| 214 | { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted" }]}` |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 215 | m := metricsStringToInterfaceArray(metricsJSON) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 216 | appMetrics = parseMetricsRules(m, appMetrics) |
| 217 | assert.Len(t, appMetrics, 2) |
| 218 | assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) |
| 219 | assert.Equal(t, "ricxappRMRReceived", appMetrics["ricxapp_RMR_Received"].ObjectInstance) |
| 220 | } |
| 221 | |
| 222 | func TestParseMetricsRulesIncrementalFillOfAppMetrics(t *testing.T) { |
| 223 | appMetrics := make(AppMetrics) |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 224 | metricsJSON1 := `{"metrics": [ |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 225 | { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }]}` |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 226 | metricsJSON2 := `{"metrics": [ |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 227 | { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted" }]}` |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 228 | m1 := metricsStringToInterfaceArray(metricsJSON1) |
| 229 | m2 := metricsStringToInterfaceArray(metricsJSON2) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 230 | appMetrics = parseMetricsRules(m1, appMetrics) |
| 231 | appMetrics = parseMetricsRules(m2, appMetrics) |
| 232 | assert.Len(t, appMetrics, 2) |
| 233 | assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) |
| 234 | assert.Equal(t, "ricxappRMRReceived", appMetrics["ricxapp_RMR_Received"].ObjectInstance) |
| 235 | } |
| 236 | |
| 237 | func TestParseXAppDescriptor(t *testing.T) { |
| 238 | appMetrics := make(AppMetrics) |
| 239 | bytes, err := ioutil.ReadFile("../../test/xApp_config_test_output.json") |
| 240 | assert.Nil(t, err) |
| 241 | |
| 242 | appMetrics = parseMetricsFromXAppDescriptor(bytes, appMetrics) |
| 243 | assert.Len(t, appMetrics, 4) |
| 244 | assert.Equal(t, "App1ExampleCounterOneObject", appMetrics["App1ExampleCounterOne"].ObjectName) |
| 245 | assert.Equal(t, "App1ExampleCounterOneObjectInstance", appMetrics["App1ExampleCounterOne"].ObjectInstance) |
| 246 | assert.Equal(t, "App1ExampleCounterTwoObject", appMetrics["App1ExampleCounterTwo"].ObjectName) |
| 247 | assert.Equal(t, "App1ExampleCounterTwoObjectInstance", appMetrics["App1ExampleCounterTwo"].ObjectInstance) |
| 248 | assert.Equal(t, "App2ExampleCounterOneObject", appMetrics["App2ExampleCounterOne"].ObjectName) |
| 249 | assert.Equal(t, "App2ExampleCounterOneObjectInstance", appMetrics["App2ExampleCounterOne"].ObjectInstance) |
| 250 | assert.Equal(t, "App2ExampleCounterTwoObject", appMetrics["App2ExampleCounterTwo"].ObjectName) |
| 251 | assert.Equal(t, "App2ExampleCounterTwoObjectInstance", appMetrics["App2ExampleCounterTwo"].ObjectInstance) |
| 252 | } |
| 253 | |
| 254 | func TestParseXAppDescriptorWithNoConfig(t *testing.T) { |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 255 | metricsJSON := `[{{"metadata": "something", "descriptor": "somethingelse"}}, |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 256 | {{"metadata": "something", "descriptor": "somethingelse"}}]` |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 257 | metricsBytes := []byte(metricsJSON) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 258 | appMetrics := make(AppMetrics) |
| 259 | appMetrics = parseMetricsFromXAppDescriptor(metricsBytes, appMetrics) |
| 260 | assert.Empty(t, appMetrics) |
| 261 | } |
| 262 | |
| 263 | func TestParseXAppDescriptorWithNoMetrics(t *testing.T) { |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 264 | metricsJSON := `[{{"metadata": "something", "descriptor": "somethingelse", "config":{}}, |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 265 | {{"metadata": "something", "descriptor": "somethingelse", "config":{}}}]` |
Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 266 | metricsBytes := []byte(metricsJSON) |
Katri Turunen | 412df96 | 2019-09-16 08:48:18 +0300 | [diff] [blame] | 267 | appMetrics := make(AppMetrics) |
| 268 | appMetrics = parseMetricsFromXAppDescriptor(metricsBytes, appMetrics) |
| 269 | assert.Empty(t, appMetrics) |
Katri Turunen | 66b7813 | 2019-09-02 10:28:52 +0300 | [diff] [blame] | 270 | } |