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 test case for internal/errors/net.go #969

Merged
merged 6 commits into from
Feb 3, 2021

Conversation

hlts2
Copy link
Contributor

@hlts2 hlts2 commented Feb 1, 2021

Signed-off-by: hlts2 [email protected]

Description:

I added the test cases for internal/errors/net.go and comment.
And fixed code comments more clearly.

grammar check passed

Related Issue:

How Has This Been Tested?:

Environment:

  • Go Version: 1.15.7
  • Docker Version: 19.03.8
  • Kubernetes Version: 1.18.2
  • NGT Version: 1.13.1

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.

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Feb 1, 2021

[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
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

@codecov
Copy link

codecov bot commented Feb 1, 2021

Codecov Report

Merging #969 (876c261) into master (660684a) will decrease coverage by 0.10%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #969      +/-   ##
==========================================
- Coverage   14.35%   14.25%   -0.11%     
==========================================
  Files         493      493              
  Lines       27898    27898              
==========================================
- Hits         4006     3978      -28     
- Misses      23647    23670      +23     
- Partials      245      250       +5     
Impacted Files Coverage Δ
internal/errors/net.go 100.00% <ø> (+100.00%) ⬆️
internal/db/storage/blob/s3/reader/reader.go 63.04% <0.00%> (-31.53%) ⬇️
internal/worker/worker.go 82.29% <0.00%> (-2.09%) ⬇️
internal/worker/queue.go 98.33% <0.00%> (-1.67%) ⬇️

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 2ce79f1...c7e9130. Read the comment docs.

internal/errors/net.go Outdated Show resolved Hide resolved
@hlts2 hlts2 changed the title [WIP] Add test case for internal/errors/net.go Add test case for internal/errors/net.go Feb 1, 2021
@hlts2 hlts2 requested a review from vankichi February 1, 2021 09:08
Comment on lines 78 to 133
{
name: "return an ErrInvalidDNSConfig when dnsRefreshDur is 5 minute, dnsCacheExp is 4 minute",
args: args{
dnsRefreshDur: 5 * time.Minute,
dnsCacheExp: 4 * time.Minute,
},
want: want{
want: New("dnsRefreshDuration > dnsCacheExp, 5m0s, 4m0s"),
},
},
{
name: "return an ErrInvalidDNSConfig when dnsRefreshDur is 0, dnsCacheExp is 0",
args: args{
dnsRefreshDur: 0,
dnsCacheExp: 0,
},
want: want{
want: New("dnsRefreshDuration > dnsCacheExp, 0s, 0s"),
},
},
{
name: "return an ErrInvalidDNSConfig when dnsRefreshDur and dnsCacheExp are the minimum number of int64",
args: args{
dnsRefreshDur: time.Duration(math.MinInt64),
dnsCacheExp: time.Duration(math.MinInt64),
},
want: want{
want: Errorf("dnsRefreshDuration > dnsCacheExp, %s, %s", time.Duration(math.MinInt64), time.Duration(math.MinInt64)),
},
},
{
name: "return an ErrInvalidDNSConfig when dnsRefreshDur and dnsCacheExp are the maximum number of int64",
args: args{
dnsRefreshDur: time.Duration(math.MaxInt64),
dnsCacheExp: time.Duration(math.MaxInt64),
},
want: want{
want: Errorf("dnsRefreshDuration > dnsCacheExp, %s, %s", time.Duration(math.MaxInt64), time.Duration(math.MaxInt64)),
},
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Could you add below case?
    1. when dnsRefreshDur is nil.
    2. when dnsCacheExp is nil.
    3. when dnsRefreshDur and dnsCacheExp is nil

Copy link
Contributor Author

@hlts2 hlts2 Feb 1, 2021

Choose a reason for hiding this comment

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

@vankichi thank you for your comment.
time.Duration is a primitive type (to be exact, an alias for primitive type), so I think we can not add a test case of nil pattern. 🤔
↓ An example of that nil is put in time.Duration type.
https://play.golang.org/p/xdI5op3KTUu

From the above, instead of the nil case pattern, I added zero value pattern 🤔
what do you think?
if I made a mistake, I am sorry.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks.
So I think we have to add below patterns

  1. when dnsRefreshDur is 0.
  2. when dnsCacheExp is 0.

and you already add the test when both of these value is 0, it'd be better renaming return an ErrInvalidDNSConfig when dnsRefreshDur is default value(or some better word), dnsCacheExp is default value (or some more better word) from return an ErrInvalidDNSConfig when dnsRefreshDur is 0, dnsCacheExp is 0.
also, it'd be better clearly if you remove these values definition from args{}.

vankichi
vankichi previously approved these changes Feb 3, 2021
Copy link
Contributor

@vankichi vankichi left a comment

Choose a reason for hiding this comment

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

LGTM

@hlts2 hlts2 requested a review from kevindiu February 3, 2021 07:07
kevindiu
kevindiu previously approved these changes Feb 3, 2021
Copy link
Contributor

@kevindiu kevindiu left a comment

Choose a reason for hiding this comment

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

LGTM

@kevindiu
Copy link
Contributor

kevindiu commented Feb 3, 2021

/rebase
/format
/approve

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Feb 3, 2021

[REBASE] Rebase triggered by kevindiu for branch: test/internal/add-newtest-for-errors-net

@vdaas-ci vdaas-ci dismissed stale reviews from kevindiu and vankichi via 3f445f2 February 3, 2021 08:09
@vdaas-ci vdaas-ci force-pushed the test/internal/add-newtest-for-errors-net branch from b2c6404 to 3f445f2 Compare February 3, 2021 08:09
@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Feb 3, 2021

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

@kevindiu kevindiu merged commit 6c2702a into master Feb 3, 2021
@kevindiu kevindiu deleted the test/internal/add-newtest-for-errors-net branch February 3, 2021 08:31
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.

4 participants