Skip to content
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

testifylint: enable go-require, float-compare and require-error rules #8027

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mmorel-35
Copy link
Contributor

@mmorel-35 mmorel-35 commented Jul 18, 2024

Thank you for contributing to Velero!

Please add a summary of your change

Enable and fixes go-require and require-error rules of testifylint linter.

Also update golangci-lint version

Does your change fix a particular issue?

Fixes #(issue)

Please indicate you've done the following:

  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Created a changelog file or added /kind changelog-not-required as a comment on this pull request.
  • Updated the corresponding documentation in site/content/docs/main.

@mmorel-35
Copy link
Contributor Author

/kind changelog-not-required

@github-actions github-actions bot added the kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes label Jul 18, 2024
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.06%. Comparing base (b5c9921) to head (da90147).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8027   +/-   ##
=======================================
  Coverage   59.06%   59.06%           
=======================================
  Files         364      364           
  Lines       30322    30322           
=======================================
  Hits        17909    17909           
  Misses      10970    10970           
  Partials     1443     1443           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mmorel-35 mmorel-35 changed the title testifylint: enable go-require and require-error rules testifylint: enable go-require, float-compare and require-error rules Jul 18, 2024
@@ -125,9 +126,9 @@ func TestWaitPVCBound(t *testing.T) {
pv, err := WaitPVCBound(context.Background(), kubeClient.CoreV1(), kubeClient.CoreV1(), test.pvcName, test.pvcNamespace, time.Millisecond)

if err != nil {
Copy link
Contributor Author

@mmorel-35 mmorel-35 Jul 19, 2024

Choose a reason for hiding this comment

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

@blackpiglet,
This condition seems odd, should it be this instead?

Suggested change
if err != nil {
if test.err != "" {

That's out of the scope of this PR but might worth a review. It's as if the assertions are done depending on the result and not there expected result.
And this happens in several places in this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. I agree with you. Although both should work, the code should check the test.err instead.

blackpiglet
blackpiglet previously approved these changes Jul 22, 2024
@mmorel-35 mmorel-35 force-pushed the testifylint/require-error branch 7 times, most recently from b0f8cfb to 3766c1c Compare July 31, 2024 17:12
blackpiglet
blackpiglet previously approved these changes Aug 1, 2024
@mmorel-35
Copy link
Contributor Author

@Lyndon-Li ,
Would you like to review this when you find the time ?

@mmorel-35 mmorel-35 force-pushed the testifylint/require-error branch 2 times, most recently from 64fbb21 to ba3d05a Compare August 8, 2024 04:41
@mmorel-35 mmorel-35 force-pushed the testifylint/require-error branch 8 times, most recently from 3431f73 to 1d672e4 Compare August 14, 2024 10:32
@mmorel-35 mmorel-35 force-pushed the testifylint/require-error branch 2 times, most recently from 144cd7f to 5f16c8a Compare August 29, 2024 09:00
@mmorel-35
Copy link
Contributor Author

mmorel-35 commented Aug 29, 2024

I have squashed and rebased all my commit now.

Please review this when you find the time.

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Comment on lines 492 to +495
if test.expectedError != nil {
assert.EqualError(t, err, test.expectedError.Error())
return
require.EqualError(t, err, test.expectedError.Error())
} else {
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like require.EqualError should be sufficient here without if/else as long as you don't call .Error()
Comparing error type to error type should be fine IMO.

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 believe it’s out of scope of this PR. This only apply best practices while keeping actual tests working. Maybe you can do a PR following your suggestion in the same time ?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-unit-tests kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants