-
Notifications
You must be signed in to change notification settings - Fork 254
ROSAENG-62105: PercentageValidator must require value greater than 0 and less than 1 #3398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,8 +68,8 @@ func PercentageValidator(val interface{}) error { | |
| return fmt.Errorf("Failed parsing '%v' into a floating-point number.", val) | ||
| } | ||
|
|
||
| if number > 1 || number < 0 { | ||
| return fmt.Errorf("Expecting a floating-point number between 0 and 1.") | ||
| if number >= 1 || number <= 0 { | ||
| return fmt.Errorf("Expecting a floating-point number greater than 0 and less than 1.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that |
||
| } | ||
|
|
||
| return nil | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,14 @@ var _ = Describe("Input Validators", Ordered, func() { | |
| Expect(PercentageValidator("-0.1")).ToNot(BeNil()) | ||
| }) | ||
|
|
||
| It("raises an error if got exactly 0", func() { | ||
| Expect(PercentageValidator("0")).ToNot(BeNil()) | ||
| }) | ||
|
|
||
| It("raises an error if got exactly 1", func() { | ||
| Expect(PercentageValidator("1")).ToNot(BeNil()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unit test update is good, but the higher-level autoscaler tests still encode the old contract: they expect the old error string and still use |
||
| }) | ||
|
|
||
| It("successfully parses a valid percentage value", func() { | ||
| Expect(PercentageValidator("0.4")).To(BeNil()) | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/rosa
Length of output: 3968
🏁 Script executed:
Repository: openshift/rosa
Length of output: 3886
Reject
NaNexplicitly.strconv.ParseFloatacceptsNaN, and this bounds check still returns nil because both comparisons are false. Addmath.IsNaN(number)to the guard and cover"NaN"inpkg/ocm/validators_test.go.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the CLI still accepts
NaN, so the validator does not yet fully enforce its own0 < x < 1contract. The same comparison pattern exists in the operator and Terraform provider, so if we address it here we should also track sibling follow-ups instead of treating it as a CLI-only nit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olucasfreitasAgreed. The CLI change should explicitly rejectNaNin this PR, while the operator and Terraform provider should receive separate follow-ups so their open-interval validation is consistent as well.Would you like me to open GitHub issues for those two sibling follow-ups, assigned to you, with links back to this PR and discussion?
✏️ Learnings added