Skip to content
This repository was archived by the owner on Oct 8, 2022. It is now read-only.

Conversation

@c1-ra
Copy link
Contributor

@c1-ra c1-ra commented Jan 31, 2022

Description

Add validation of the user input into the runner CLI in Config.Validate() method and related tests.

@c1-ra c1-ra linked an issue Jan 31, 2022 that may be closed by this pull request
@c1-ra c1-ra changed the title Dev/implement proper error handling dev : implement proper error handling Jan 31, 2022
@c1-ra c1-ra force-pushed the dev/implement-proper-error-handling branch 5 times, most recently from e7e704f to 6b882b0 Compare January 31, 2022 13:12
@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2022

Codecov Report

Merging #26 (4f0afa3) into main (e03a1aa) will increase coverage by 4.44%.
The diff coverage is 100.00%.

❗ Current head 4f0afa3 differs from pull request most recent head 79eed3c. Consider uploading reports for the commit 79eed3c to get more accurate results
Impacted file tree graph

@@            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              
Flag Coverage Δ
unittests 78.70% <100.00%> (+4.44%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
config/config.go 84.48% <100.00%> (+9.48%) ⬆️
config/error.go 100.00% <100.00%> (ø)
config/file/parse.go 65.95% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e03a1aa...79eed3c. Read the comment docs.

@c1-ra c1-ra force-pushed the dev/implement-proper-error-handling branch from 6b882b0 to 2230d58 Compare January 31, 2022 15:45
@c1-ra c1-ra changed the title dev : implement proper error handling dev : implement proper error handling for user input validation Jan 31, 2022
@c1-ra c1-ra marked this pull request as ready for review January 31, 2022 15:48
@c1-ra c1-ra force-pushed the dev/implement-proper-error-handling branch from 2230d58 to dfc11e0 Compare January 31, 2022 15:56
@c1-ra c1-ra requested a review from GregoryAlbouy February 1, 2022 09:27
@c1-ra c1-ra force-pushed the dev/implement-proper-error-handling branch from eb8f096 to c1ffab1 Compare February 1, 2022 09:34
@c1-ra c1-ra force-pushed the dev/implement-proper-error-handling branch from c1ffab1 to d2cd105 Compare February 1, 2022 09:48
Copy link
Member

@GregoryAlbouy GregoryAlbouy left a 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
Comment on lines 80 to 81
if cfg.RunnerOptions.Requests < 0 {
if cfg.RunnerOptions.Requests != -1 {
Copy link
Member

@GregoryAlbouy GregoryAlbouy Feb 1, 2022

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:

Suggested change
if cfg.RunnerOptions.Requests < 0 {
if cfg.RunnerOptions.Requests != -1 {
if cfg.RunnerOptions.Requests < 1 && cfg.RunnerOptions.Requests != -1 {

Copy link
Contributor Author

@c1-ra c1-ra Feb 1, 2022

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.

Copy link
Member

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.

Copy link
Contributor Author

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...

@c1-ra c1-ra requested a review from GregoryAlbouy February 1, 2022 11:41
@c1-ra c1-ra force-pushed the dev/implement-proper-error-handling branch 9 times, most recently from e6b0150 to bba6d94 Compare February 1, 2022 15:38
@c1-ra c1-ra merged commit 9656fd0 into main Feb 3, 2022
@moreirathomas moreirathomas deleted the dev/implement-proper-error-handling branch February 3, 2022 10:11
@GregoryAlbouy GregoryAlbouy restored the dev/implement-proper-error-handling branch February 3, 2022 17:52
@GregoryAlbouy GregoryAlbouy deleted the dev/implement-proper-error-handling branch February 3, 2022 17:52
GregoryAlbouy pushed a commit that referenced this pull request Feb 3, 2022
* 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 <>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement proper error handling for config object

5 participants