forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanagerdiagnosticdata_test.go
111 lines (101 loc) · 2.81 KB
/
managerdiagnosticdata_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
)
var managerDiagnosticDataBody = `{
"@odata.type": "#ManagerDiagnosticData.v1_2_2.ManagerDiagnosticData",
"Id": "ManagerDiagnosticData",
"Name": "Manager Diagnostic Data",
"I2CBuses": [
{
"I2CBusName": "i2c-0",
"TotalTransactionCount": 10000,
"BusErrorCount": 12,
"NACKCount": 34
},
{
"I2CBusName": "i2c-1",
"TotalTransactionCount": 20000,
"BusErrorCount": 56,
"NACKCount": 78
}
],
"MemoryStatistics": {
"TotalBytes": 1013052000,
"UsedBytes": 45084000,
"FreeBytes": 894820000,
"SharedBytes": 19864000,
"BuffersAndCacheBytes": 73148000,
"AvailableBytes": 928248000
},
"ProcessorStatistics": {
"KernelPercent": 12.34,
"UserPercent": 23.45
},
"TopProcesses": [
{
"CommandLine": "dbus-broker",
"UserTimeSeconds": 14400,
"KernelTimeSeconds": 10800,
"ResidentSetSizeBytes": 2300000
},
{
"CommandLine": "swampd",
"UserTimeSeconds": 13200,
"KernelTimeSeconds": 8441,
"ResidentSetSizeBytes": 8883000
},
{
"CommandLine": "ipmid",
"UserTimeSeconds": 13100,
"KernelTimeSeconds": 6650,
"ResidentSetSizeBytes": 23400000
},
{
"CommandLine": "phosphor-hwmon-readd -i iface1",
"UserTimeSeconds": 5100,
"KernelTimeSeconds": 3200,
"ResidentSetSizeBytes": 564000
}
],
"BootTimeStatistics": {
"FirmwareTimeSeconds": 42.3,
"LoaderTimeSeconds": 12.3,
"KernelTimeSeconds": 33.1,
"InitrdTimeSeconds": 3.2,
"UserSpaceTimeSeconds": 81.1
},
"MemoryECCStatistics": {
"CorrectableECCErrorCount": 1,
"UncorrectableECCErrorCount": 2
},
"@odata.id": "/redfish/v1/Managers/BMC/ManagerDiagnosticData"
}`
// TestManagerDiagnosticData tests the parsing of ManagerDiagnosticData objects.
func TestManagerDiagnosticData(t *testing.T) {
var result ManagerDiagnosticData
err := json.NewDecoder(strings.NewReader(managerDiagnosticDataBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "ManagerDiagnosticData", result.ID)
assertEquals(t, "Manager Diagnostic Data", result.Name)
assertEquals(t, "i2c-0", result.I2CBuses[0].I2CBusName)
if result.MemoryStatistics.TotalBytes != 1013052000 {
t.Errorf("Unexpected memory stats total bytes: %d", result.MemoryStatistics.TotalBytes)
}
if result.ProcessorStatistics.KernelPercent != 12.34 {
t.Errorf("Unexpected processor stats kernel percent: %.2f", result.ProcessorStatistics.KernelPercent)
}
if result.BootTimeStatistics.LoaderTimeSeconds != 12.3 {
t.Errorf("Unexpected memory stats total bytes: %.2f", result.BootTimeStatistics.LoaderTimeSeconds)
}
if result.MemoryECCStatistics.CorrectableECCErrorCount != 1 {
t.Errorf("Unexpected memory ECC stats correctable error count: %d", result.MemoryECCStatistics.CorrectableECCErrorCount)
}
}