Skip to content

defer reader.Close() in body_limit_test #2344

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

Closed
wants to merge 2 commits into from

Conversation

zeek0x
Copy link
Contributor

@zeek0x zeek0x commented Nov 22, 2022

limitedReader.Close function will be tested by this change.
As a result, the code coverage of body_limit increases.

@codecov
Copy link

codecov bot commented Nov 22, 2022

Codecov Report

Base: 92.38% // Head: 92.59% // Increases project coverage by +0.20% 🎉

Coverage data is based on head (186325f) compared to base (3c4d3b3).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2344      +/-   ##
==========================================
+ Coverage   92.38%   92.59%   +0.20%     
==========================================
  Files          37       37              
  Lines        4454     4441      -13     
==========================================
- Hits         4115     4112       -3     
+ Misses        247      239       -8     
+ Partials       92       90       -2     
Impacted Files Coverage Δ
middleware/jwt.go 92.98% <100.00%> (ø)
middleware/body_limit.go 84.00% <0.00%> (+4.00%) ⬆️
echo_fs.go 92.50% <0.00%> (+7.55%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@aldas
Copy link
Contributor

aldas commented Nov 23, 2022

it is not very useful or proper way to test close. I would not mind or even notice if this would be with some other changes but alone this stands out - as artificially improving coverage. This is not what tests suppose to do or are meant for.

If you feel that close needs to be checked that it does what it is supposed to - please write proper test for it.

@aldas
Copy link
Contributor

aldas commented Nov 24, 2022

This is not useful at all.

I understand that you have checked the coverage of that file and decided that out 4 places (full coverage of that file) that are not covered yet you want to cover that method. Even though reader that is being called is io.NopCloser which has implementation func (nopCloser) Close() error { return nil }

but you choose not to test skipper parts which would be actually useful and provide more coverage

config.Skipper = DefaultBodyLimitConfig.Skipper

return next(c)

I am going to accept this PR if you add at least one of these options:
a) proper testcase for close that check that calling close actually calls Close on wrapped reader
b) separate testcase for skipper
c) separate testcase for panic

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