Skip to content

Commit

Permalink
Merge pull request #138 from stmcginnis/updatenames
Browse files Browse the repository at this point in the history
Handle json name being different than property name
  • Loading branch information
stmcginnis authored Apr 24, 2021
2 parents 3c6d7f1 + 18aed44 commit dd98a92
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (e *Entity) Update(originalEntity, currentEntity reflect.Value, allowedUpda
continue
}
fieldName := originalEntity.Type().Field(i).Name
jsonName := originalEntity.Type().Field(i).Tag.Get("json")
if jsonName != "" {
fieldName = jsonName
}
originalValue := originalEntity.Field(i).Interface()
currentValue := currentEntity.Field(i).Interface()
if originalValue == nil && currentValue == nil {
Expand All @@ -72,11 +76,9 @@ func (e *Entity) Update(originalEntity, currentEntity reflect.Value, allowedUpda
payload[fieldName] = currentValue
} else if reflect.TypeOf(originalValue).Kind() != reflect.Map {
if originalValue != currentValue {
// TODO: Handle JSON name being different than field name
payload[fieldName] = currentValue
}
} else if !reflect.DeepEqual(originalValue, currentValue) {
// TODO: Handle JSON name being different than field name
payload[fieldName] = currentValue
}
}
Expand Down
5 changes: 5 additions & 0 deletions redfish/manageraccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestManagerAccountUpdate(t *testing.T) {
result.Enabled = false
result.Locked = false
result.Password = "Test"
result.RoleID = "Administrator"
err = result.Update()

if err != nil {
Expand All @@ -92,4 +93,8 @@ func TestManagerAccountUpdate(t *testing.T) {
if !strings.Contains(calls[0].Payload, "Password:Test") {
t.Errorf("Unexpected Password update payload: %s", calls[0].Payload)
}

if !strings.Contains(calls[0].Payload, "RoleId:Administrator") {
t.Errorf("Unexpected Role ID update payload: %s", calls[0].Payload)
}
}

0 comments on commit dd98a92

Please sign in to comment.