-
Notifications
You must be signed in to change notification settings - Fork 0
dev : implement proper error handling for user input validation #26
Conversation
e7e704f to
6b882b0
Compare
Codecov Report
@@ Coverage Diff @@
## main #26 +/- ##
==========================================
+ Coverage 74.26% 78.70% +4.44%
==========================================
Files 5 6 +1
Lines 136 155 +19
==========================================
+ Hits 101 122 +21
+ Misses 24 22 -2
Partials 11 11
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
6b882b0 to
2230d58
Compare
2230d58 to
dfc11e0
Compare
eb8f096 to
c1ffab1
Compare
c1ffab1 to
d2cd105
Compare
GregoryAlbouy
left a comment
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.
Nice! Just a couple of changes for me and we're good to go!
config/config.go
Outdated
| if cfg.RunnerOptions.Requests < 0 { | ||
| if cfg.RunnerOptions.Requests != -1 { |
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.
We can avoid that extra nesting using &&, also I think 0 should be an invalid value for requests:
| if cfg.RunnerOptions.Requests < 0 { | |
| if cfg.RunnerOptions.Requests != -1 { | |
| if cfg.RunnerOptions.Requests < 1 && cfg.RunnerOptions.Requests != -1 { |
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 first used &&, but gocognit was complaining that Validate() was too complex :(
https://github.com/benchttp/runner/runs/5018964117?check_suite_focus=true
It seems less complex to me with && but nesting another condition seemed to pass the checks, so I went with it. Do you have another method in mind that could work to pass the checks too?
It is right though that 0 should also be invalid.
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.
Well if gocognit considers a single && more complex than a nested if then it doesn't do its job correctly 🤷♂️
I suggest we shut it down and remove it from .golangci.yml.
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 have used //nolint on the method for the moment, if we run into this problem again, we can remove gocognit completely...
e6b0150 to
bba6d94
Compare
* Add `ErrInvalid` to `config` package * Add `Config.Validate()` method * Add call to `Config.Validate()` in `makeRunnerConfig` * Add tests for `Config.Validate()` * Reformat with golangci-lint * Modify `config.New` and related test * Modify `url.Parse(url)` to `url.ParseRequestURI(url)` Co-authored-by: C <>
Description
Add validation of the user input into the runner CLI in
Config.Validate()method and related tests.