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

chore(utils): test sanitizing empty addr #2998

Closed
wants to merge 2 commits into from

Conversation

estensen
Copy link
Contributor

Add coverage to the non-happy path

@github-actions github-actions bot added the external Issues created by non node team members label Dec 11, 2023
@ramin ramin added the kind:testing Related to unit tests label Dec 11, 2023
Copy link
Collaborator

@ramin ramin left a comment

Choose a reason for hiding this comment

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

this is cool, lets go a step further, and create a named var in the address.go file (ErrInvalidIP maybe) then instead of the expErr being a bool, we can make it an error and give it nil or the expected error and test require.EqualErorr or similar as part of the test, then we can skip the !tt.expErr and just test that its nil or the ErrInvalidIP

libs/utils/address_test.go Outdated Show resolved Hide resolved
Comment on lines 32 to +38
require.Equal(t, tt.want, got)
if tt.err != nil {
require.Error(t, err)
require.True(t, errors.Is(err, tt.err))
} else {
require.NoError(t, err)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wanted this

require.Equal(t, tt.want, got)
require.ErrorIs(t, tt.err, err)

But couldn't get it to work

Error:      	Target error should be in err chain:
            	            	expected: "invalid IP address or hostname given: "
            	            	in chain: "invalid IP address or hostname given"
            	Test:       	TestSanitizeAddr/#00

@estensen estensen requested a review from ramin December 14, 2023 12:58
Copy link
Collaborator

@ramin ramin left a comment

Choose a reason for hiding this comment

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

lgtm :shipit:

@codecov-commenter
Copy link

codecov-commenter commented Dec 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b709b4e) 50.96% compared to head (3da62a2) 50.76%.
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2998      +/-   ##
==========================================
- Coverage   50.96%   50.76%   -0.21%     
==========================================
  Files         168      168              
  Lines       11038    11022      -16     
==========================================
- Hits         5626     5595      -31     
- Misses       4908     4928      +20     
+ Partials      504      499       -5     

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

Comment on lines +33 to +38
if tt.err != nil {
require.Error(t, err)
require.True(t, errors.Is(err, tt.err))
} else {
require.NoError(t, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

You can simplify this by just doing assert.ErrorIs(t, err, tt.err)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@renaynay created a replacement with the change here to speed us along #3051

ramin added a commit that referenced this pull request Jan 8, 2024
<!--
Thank you for submitting a pull request!

Please make sure you have reviewed our contributors guide before
submitting your
first PR.

Please ensure you've addressed or included references to any related
issues.

Tips:
- Use keywords like "closes" or "fixes" followed by an issue number to
automatically close related issues when the PR is merged (e.g., "closes
#123" or "fixes #123").
- Describe the changes made in the PR.
- Ensure the PR has one of the required tags (kind:fix, kind:misc,
kind:break!, kind:refactor, kind:feat, kind:deps, kind:docs, kind:ci,
kind:chore, kind:testing)

-->

in kind replacement of
#2998 with the
simplified require assertion

---------

Co-authored-by: Håvard Anda Estensen <haavard.ae@gmail.com>
@ramin ramin closed this Jan 8, 2024
distractedm1nd pushed a commit that referenced this pull request Jan 10, 2024
<!--
Thank you for submitting a pull request!

Please make sure you have reviewed our contributors guide before
submitting your
first PR.

Please ensure you've addressed or included references to any related
issues.

Tips:
- Use keywords like "closes" or "fixes" followed by an issue number to
automatically close related issues when the PR is merged (e.g., "closes
#123" or "fixes #123").
- Describe the changes made in the PR.
- Ensure the PR has one of the required tags (kind:fix, kind:misc,
kind:break!, kind:refactor, kind:feat, kind:deps, kind:docs, kind:ci,
kind:chore, kind:testing)

-->

in kind replacement of
#2998 with the
simplified require assertion

---------

Co-authored-by: Håvard Anda Estensen <haavard.ae@gmail.com>
renaynay pushed a commit to renaynay/celestia-node that referenced this pull request Jan 15, 2024
<!--
Thank you for submitting a pull request!

Please make sure you have reviewed our contributors guide before
submitting your
first PR.

Please ensure you've addressed or included references to any related
issues.

Tips:
- Use keywords like "closes" or "fixes" followed by an issue number to
automatically close related issues when the PR is merged (e.g., "closes
#123" or "fixes #123").
- Describe the changes made in the PR.
- Ensure the PR has one of the required tags (kind:fix, kind:misc,
kind:break!, kind:refactor, kind:feat, kind:deps, kind:docs, kind:ci,
kind:chore, kind:testing)

-->

in kind replacement of
celestiaorg#2998 with the
simplified require assertion

---------

Co-authored-by: Håvard Anda Estensen <haavard.ae@gmail.com>
renaynay pushed a commit to renaynay/celestia-node that referenced this pull request Jan 15, 2024
<!--
Thank you for submitting a pull request!

Please make sure you have reviewed our contributors guide before
submitting your
first PR.

Please ensure you've addressed or included references to any related
issues.

Tips:
- Use keywords like "closes" or "fixes" followed by an issue number to
automatically close related issues when the PR is merged (e.g., "closes
#123" or "fixes #123").
- Describe the changes made in the PR.
- Ensure the PR has one of the required tags (kind:fix, kind:misc,
kind:break!, kind:refactor, kind:feat, kind:deps, kind:docs, kind:ci,
kind:chore, kind:testing)

-->

in kind replacement of
celestiaorg#2998 with the
simplified require assertion

---------

Co-authored-by: Håvard Anda Estensen <haavard.ae@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Issues created by non node team members kind:testing Related to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants