Skip to content

test: address MaxPowerWatts review comments from #55 - #57

Merged
bbrown-cw merged 1 commit into
mainfrom
chassis-maxpowerwatts-test-followup
Oct 19, 2026
Merged

bbrown-cw merged 1 commit into
mainfrom
chassis-maxpowerwatts-test-followup

Conversation

@bbrown-cw

Copy link
Copy Markdown

follow up on comments from #55

Comment thread redfish/chassis_test.go
Comment on lines +301 to +304
// TestChassisZeroMaxPowerWatts ensures a reported 0 is distinguishable from absent.
func TestChassisZeroMaxPowerWatts(t *testing.T) {
var result Chassis
err := json.NewDecoder(strings.NewReader(`{"Id": "1", "MaxPowerWatts": 0}`)).Decode(&result)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This test checks only the reported-0 case, and no test covers "MaxPowerWatts": null.

The doc comment says 0 is distinguishable from absent, but the absent check lives in TestMinimumChassis on the Supermicro RAID fixture. A change to that fixture could drop it, and nothing here would notice.

The schema also types the field as ["number", "null"], and a BMC that sends null should decode to nil like an absent field. Both cases pass today through encoding/json. A later vendor fallback on this field (like toFloat32 in redfish/power.go) could break either one without failing a test.

Please make this a small table with absent, null and 0 cases, each checking for nil or the value.

Comment thread oem/smc/chassis_test.go
t.Errorf("Unexpected board ID: %s", result.BoardID)
}

if result.MaxPowerWatts == nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The setup steps in this test report errors with t.Errorf and keep going, so a setup failure panics before it reaches this check.

If the fixture stops decoding, FromChassis returns nil, err (oem/smc/chassis_test.go:94), and result.ID at line 97 panics with a nil dereference. The decode check at oem/smc/chassis_test.go:89 has the same problem. The new redfish test in this PR uses t.Fatalf for the same step.

Please switch both setup checks to t.Fatalf.

Comment thread redfish/chassis_test.go

if result.MaxPowerWatts == nil || *result.MaxPowerWatts != 1200 {
t.Errorf("Received invalid max power watts: %v", result.MaxPowerWatts)
if result.MaxPowerWatts == nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking: MinPowerWatts is still a float64 (redfish/chassis.go:299), and the comment about it on #55 has no reply.

It has the same missing-vs-zero problem that this PR tests for MaxPowerWatts. 0 W is a valid lower bound, so a caller can't read 0 as "not reported", and a BMC that sends only "MaxPowerWatts": 1200 decodes to a min of 0. Converting it later is a second type change, with its own follow-up PR in each consumer.

Please change MinPowerWatts to *float64 with the same tests, or reply on #55 if it should wait.

@c4milo c4milo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left some nits and 1 non-blocking comment.

@bbrown-cw
bbrown-cw merged commit 2dafbd4 into main Oct 19, 2026
2 checks passed
@bbrown-cw
bbrown-cw deleted the chassis-maxpowerwatts-test-followup branch October 19, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants