-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
- Loading branch information
1 parent
b94784f
commit 17ed8aa
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} |