Skip to content

Commit

Permalink
Merge pull request stmcginnis#153 from leslie-qiwa/add-oem
Browse files Browse the repository at this point in the history
add oem property for root service object
  • Loading branch information
stmcginnis committed Jun 18, 2021
2 parents 653ea95 03846ee commit 16f7bb2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions serviceroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 99,9 @@ type Service struct {
// Managers shall only contain a reference to a collection of resources that
// comply to the Managers schema.
managers string
// Oem contains all the vendor specific actions. It is vendor responsibility to parse
// this field accordingly
Oem json.RawMessage
// Product shall include the name of the product represented by this Redfish
// service.
Product string
Expand Down Expand Up @@ -175,6 178,7 @@ func (serviceroot *Service) UnmarshalJSON(b []byte) error {
Links struct {
Sessions common.Link
}
Oem json.RawMessage // OEM message will be stored here
}

err := json.Unmarshal(b, &t)
Expand Down Expand Up @@ -203,6 207,7 @@ func (serviceroot *Service) UnmarshalJSON(b []byte) error {
serviceroot.sessionService = string(t.SessionService)
serviceroot.telemetryService = string(t.TelemetryService)
serviceroot.updateService = string(t.UpdateService)
serviceroot.Oem = t.Oem

return nil
}
Expand Down
44 changes: 44 additions & 0 deletions serviceroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 193,47 @@ func TestServiceRoot(t *testing.T) {
t.Errorf("Invalid UpdateService link: %s", result.updateService)
}
}

const oem = `{
"Dell": {
"@odata.context": "/redfish/v1/$metadata#DellServiceRoot.DellServiceRoot",
"@odata.type": "#DellServiceRoot.v1_0_0.DellServiceRoot",
"ManagerMACAddress": "4c:d9:8f:00:11:34",
"ServiceTag": "C3H3853"
}
}`

var serviceRootBodyOEM = strings.NewReader(
`{
"@odata.context": "/redfish/v1/$metadata#ServiceRoot.ServiceRoot",
"@odata.type": "#ServiceRoot.v1_5_1.ServiceRoot",
"@odata.id": "/redfish/v1/ServiceRoot",
"Id": "ServiceRoot-1",
"Name": "ServiceRootOne",
"Description": "ServiceRoot One",
"Oem":` oem `,
"Vendor": "Dell"
}`)

// TestServiceRootOEM tests the parsing of ServiceRoot objects with OEM field.
func TestServiceRootOEM(t *testing.T) {
var result Service
err := json.NewDecoder(serviceRootBodyOEM).Decode(&result)

if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}

if result.ID != "ServiceRoot-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}

if result.Oem == nil {
t.Error("Invalid Oem link")
}
oemExp := strings.TrimSpace(oem)
oemObt := strings.TrimSpace(string(result.Oem))
if oemExp != oemObt {
t.Errorf("Expect\n%s\n,Obtain\n%s", oemExp, oemObt)
}
}

0 comments on commit 16f7bb2

Please sign in to comment.