From 17ed8aabcc64863084ebf8488da05d1e66f3fa3a Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Fri, 19 Apr 2024 16:20:02 -0500 Subject: [PATCH] Add MetricDefinition test coverage Signed-off-by: Sean McGinnis --- redfish/metricdefinition_test.go | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 redfish/metricdefinition_test.go diff --git a/redfish/metricdefinition_test.go b/redfish/metricdefinition_test.go new file mode 100644 index 00000000..549f9d05 --- /dev/null +++ b/redfish/metricdefinition_test.go @@ -0,0 +1,50 @@ +// +// SPDX-License-Identifier: BSD-3-Clause +// + +package redfish + +import ( + "encoding/json" + "fmt" + "strings" + "testing" +) + +var metricDefinitonBody = `{ + "@odata.type": "#MetricDefinition.v1_3_1.MetricDefinition", + "@odata.context": "/redfish/v1/$metadata#MetricDefinition.MetricDefinition", + "@odata.id": "/redfish/v1/TelemetryService/MetricDefinitions/VoltageStatus", + "Id": "VoltageStatus", + "Name": "Voltage status Metric Definition", + "Description": "Status of the Voltage of Small Form Factor pluggable(SFP) Tranceiver", + "MetricType": "Discrete", + "MetricDataType": "Enumeration", + "Accuracy": 0, + "SensingInterval": "PT60.0S", + "DiscreteValues": [ + "Unknown", + "OK", + "Warning", + "Critical" + ] + }` + +// TestMetricDefinition tests the parsing of MetricDefinition objects. +func TestMetricDefinition(t *testing.T) { + var result MetricDefinition + err := json.NewDecoder(strings.NewReader(metricDefinitonBody)).Decode(&result) + + if err != nil { + t.Errorf("Error decoding JSON: %s", err) + } + + assertEquals(t, "VoltageStatus", result.ID) + assertEquals(t, "Voltage status Metric Definition", result.Name) + assertEquals(t, "Status of the Voltage of Small Form Factor pluggable(SFP) Tranceiver", result.Description) + assertEquals(t, "0", fmt.Sprintf("%.0f", result.Accuracy)) + assertEquals(t, "PT60.0S", result.SensingInterval) + assertEquals(t, "4", fmt.Sprintf("%d", len(result.DiscreteValues))) + assertEquals(t, "Discrete", string(result.MetricType)) + assertEquals(t, "Enumeration", string(result.MetricDataType)) +}