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

Add internal/net test #615

Merged
merged 9 commits into from
Aug 13, 2020
Merged

Add internal/net test #615

merged 9 commits into from
Aug 13, 2020

Conversation

kevindiu
Copy link
Contributor

@kevindiu kevindiu commented Aug 7, 2020

Author review required.

Description:

This PR implements test case for internal/net/net.go.
This PR also include the following changes:

Bug fix:

Refactor:

Related Issue:

How Has This Been Tested?:

Environment:

  • Go Version: 1.14.4
  • Docker Version: 19.03.8
  • Kubernetes Version: 1.18.2
  • NGT Version: 1.12.0

Types of changes:

  • Bug fix [type/bug]
  • New feature [type/feature]
  • Add tests [type/test]
  • Security related changes [type/security]
  • Add documents [type/documentation]
  • Refactoring [type/refactoring]
  • Update dependencies [type/dependency]
  • Update benchmarks and performances [type/bench]
  • Update CI [type/ci]

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Checklist:

  • I have read the CONTRIBUTING document.
  • I have checked open Pull Requests for the similar feature or fixes?
  • I have added tests and benchmarks to cover my changes.
  • I have ensured all new and existing tests passed.
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly.

@pull-assistant
Copy link

pull-assistant bot commented Aug 7, 2020

Score: 0.94

Best reviewed: commit by commit


Optimal code review plan

     refactor and add net test

     fix

     revert changes

     add comments

     fix type

     fix

     fix deepsource

     add comment

     fix CI

Powered by Pull Assistant. Last update 72dc772 ... 77659e5. Read the comment docs.

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Aug 7, 2020

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 💌 /changelog - add changelog comment
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • /rebase - rebase master

@kevindiu kevindiu changed the title Create net test internal/net test Aug 7, 2020
@kevindiu
Copy link
Contributor Author

kevindiu commented Aug 7, 2020

/rebase

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Aug 7, 2020

[REBASE] Rebase triggered by kevindiu for branch: test/internal/net

@codecov
Copy link

codecov bot commented Aug 7, 2020

Codecov Report

Merging #615 into master will increase coverage by 0.25%.
The diff coverage is 69.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #615      +/-   ##
==========================================
+ Coverage   13.73%   13.99%   +0.25%     
==========================================
  Files         409      409              
  Lines       21516    21519       +3     
==========================================
+ Hits         2956     3011      +55     
+ Misses      18285    18229      -56     
- Partials      275      279       +4     
Impacted Files Coverage Δ
internal/errors/net.go 0.00% <ø> (ø)
internal/net/net.go 87.30% <69.23%> (+87.30%) ⬆️
internal/worker/queue.go 95.65% <0.00%> (-2.90%) ⬇️
internal/worker/worker.go 86.36% <0.00%> (+1.81%) ⬆️

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 13c5365...77659e5. Read the comment docs.

func SplitHostPort(hostport string) (host string, port uint16, err error) {
switch {
case strings.HasPrefix(hostport, "::"):
hostport = localIPv6 + hostport
hostport = localIPv6 + hostport[2:]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The format of IPv6 address with port number should be [addr]:port, the logic of line 96 is incorrect, should I fix it? @kpango @rinx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or if the hostport do not contains port number, there are no [] to wrap the address, instead the host should use the hostport with port defaultPort

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 suggest:

switch {
case hostport == "::1":
    hostport = "[" + localIPv6 + "]:" + defaultPort
........

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or we can return directly.

switch {
case hostport == "::1":
    return localIPv6, defaultPort, nil

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we have to make 2 changes, this case was implemented for detecting loopback address, if there is no port definition on hostport string, we can use default port but in this case we have to check there is a port in hostport string or not, and if exists we have to parse it.
one more thing as you mentioned, loopback addr is ::1 but it also can be written as :: or 0:0:0:0:0:0:0:1. so we have to check them

Copy link
Collaborator

@kpango kpango Aug 11, 2020

Choose a reason for hiding this comment

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

Could you please read RFC more carefully, In RFC5952 (https://tools.ietf.org/html/rfc5952#section-6) there are 6 types of ipv6 w/ port format we should support them.
Your code seems support only 1 format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kpango
May I confirm that this switch case statement is checking if hostport contains hostname or port number only and use the default value if not exists?

For example, line 98-99 use the default local IPv4 address if the host is missing.
I think IPv6 do not have empty host case so we don't need to support it.

But I think IPv6 have empty port, so I wrote the logic above.

BTW net.SplitHostPort doesn't support all RFC format.
https://golang.org/src/net/ipsock.go?s=4766:4832#L146

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how should we work on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
hostport = localIPv6 + hostport[2:]
// hostport = localIPv6 + hostport[2:]

Copy link
Contributor

Choose a reason for hiding this comment

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

@kevindiu
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by kevindiu for branch: test/internal/net

internal/errors/net.go Outdated Show resolved Hide resolved
internal/errors/net.go Outdated Show resolved Hide resolved
internal/net/net_test.go Outdated Show resolved Hide resolved
internal/net/net_test.go Outdated Show resolved Hide resolved
internal/net/net_test.go Outdated Show resolved Hide resolved
internal/net/net_test.go Outdated Show resolved Hide resolved
@kevindiu kevindiu changed the title internal/net test [WIP] internal/net test Aug 12, 2020
internal/net/net.go Outdated Show resolved Hide resolved
@kevindiu
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by kevindiu for branch: test/internal/net

@kevindiu kevindiu changed the title [WIP] internal/net test Add internal/net test Aug 12, 2020
internal/net/net_test.go Outdated Show resolved Hide resolved
internal/net/net_test.go Outdated Show resolved Hide resolved
internal/net/net_test.go Outdated Show resolved Hide resolved
@kevindiu kevindiu requested a review from hlts2 August 12, 2020 06:52
@kevindiu
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by kevindiu for branch: test/internal/net

@kevindiu kevindiu marked this pull request as ready for review August 12, 2020 08:24
internal/net/net.go Outdated Show resolved Hide resolved
internal/net/net.go Show resolved Hide resolved
internal/net/net.go Outdated Show resolved Hide resolved
vankichi
vankichi previously approved these changes Aug 13, 2020
@kpango
Copy link
Collaborator

kpango commented Aug 13, 2020

/rebase
/format
/approve

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by kpango for branch: test/internal/net

@vdaas-ci
Copy link
Collaborator

[FORMAT] Updating license headers and formatting go codes triggered by kpango.

vdaas-ci
vdaas-ci previously approved these changes Aug 13, 2020
Copy link
Collaborator

@vdaas-ci vdaas-ci left a comment

Choose a reason for hiding this comment

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

[APPROVED] This PR is approved by kpango.

@kevindiu kevindiu requested review from hlts2 and vankichi and removed request for vankichi August 13, 2020 09:58
@kpango kpango merged commit aca45ea into master Aug 13, 2020
@kpango kpango deleted the test/internal/net branch August 13, 2020 10:04
@vdaas-ci vdaas-ci mentioned this pull request Sep 2, 2020
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants