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

Create internal/net/http/client option test #831

Merged
merged 7 commits into from
Nov 18, 2020
Merged

Conversation

kevindiu
Copy link
Contributor

@kevindiu kevindiu commented Nov 12, 2020

Description:

This PR implements http client option test.
This PR also includes the following changes:

  • [Test related] add the comparator implementation of transport to the client_test.go
  • [Refactor] Refactor the error returned from the option and handle it in New()

Related Issue:

How Has This Been Tested?:

Environment:

  • Go Version: 1.15.2
  • Docker Version: 19.03.8
  • Kubernetes Version: 1.18.2
  • NGT Version: 1.12.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

[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
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

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

@vdaas-ci
Copy link
Collaborator

[REBASE] Failed to rebase.

internal/net/http/client/client_test.go Show resolved Hide resolved
name: "set header success",
args: args{
header: http.Header(
map[string][]string{"dummy": []string{"val"}},
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
File is not gofmt-ed with -s (gofmt)

internal/net/http/client/client_test.go Show resolved Hide resolved
internal/net/http/client/client_test.go Show resolved Hide resolved
internal/net/http/client/client_test.go Show resolved Hide resolved
internal/net/http/client/client_test.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Nov 12, 2020

Codecov Report

Merging #831 (56d099b) into master (a89ddb6) will increase coverage by 0.39%.
The diff coverage is 77.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #831      +/-   ##
==========================================
+ Coverage   18.15%   18.55%   +0.39%     
==========================================
  Files         422      422              
  Lines       19554    19572      +18     
==========================================
+ Hits         3550     3631      +81     
+ Misses      15793    15733      -60     
+ Partials      211      208       -3     
Impacted Files Coverage Δ
internal/db/nosql/cassandra/cassandra_mock.go 100.00% <ø> (ø)
internal/net/http/client/client.go 0.00% <0.00%> (ø)
internal/net/http/client/option.go 100.00% <100.00%> (+100.00%) ⬆️
internal/worker/queue.go 95.00% <0.00%> (-3.34%) ⬇️
internal/file/watch/watch.go 90.00% <0.00%> (-1.00%) ⬇️
internal/worker/worker.go 83.33% <0.00%> (+1.04%) ⬆️
internal/errgroup/group.go 93.93% <0.00%> (+1.51%) ⬆️

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 2e09b7e...229806e. Read the comment docs.

@kevindiu kevindiu requested a review from hlts2 November 12, 2020 03:32
@kevindiu
Copy link
Contributor Author

/format

@vdaas-ci
Copy link
Collaborator

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

hlts2
hlts2 previously approved these changes Nov 16, 2020
Copy link
Contributor

@hlts2 hlts2 left a comment

Choose a reason for hiding this comment

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

LGTM

@vankichi
Copy link
Contributor

@kevindiu
why did you change client_test.go?
I think it is not needed in this PR 🤔

@kevindiu
Copy link
Contributor Author

@vankichi I think it is better to write transport comparator in client_test not in option_test, so I changed client_test implementation

internal/net/http/client/option_test.go Show resolved Hide resolved
internal/net/http/client/option_test.go Show resolved Hide resolved
internal/net/http/client/option_test.go Show resolved Hide resolved
{
name: "set timeout failed with empty value",
args: args{
dur: "",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vankichi Do you mean this line dur: "" is not need?
I think it is more clear to write even if the value is the default value of the type, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

but, as you know, the default value of string is "".
I do not care but it is not necessary, also your opinion is right.
It is the decision problem, any test rule in coding guideline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no such rule in the coding guideline.
I am not sure if I am correct, as all we know the default value of string is "" in golang, we can decide to write this definition or not by ourself (not standardize for everyone, but preference for each developer), what do you think?

Even if we decide to use this pattern, I think this rule only applies to test code, so I think it is better not to write it in coding guideline.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is clear creating test case with no input test case like as int pattern.
And, I think we consider about the unit test practice and create new document for unit testing.
How about it?

Copy link
Contributor Author

@kevindiu kevindiu Nov 16, 2020

Choose a reason for hiding this comment

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

I think it is clear creating test case with no input test case like as int pattern.

I think users need to input the value in option (for example WithXXX(""), so I think writing "" is more realistic and easier to understand.

I think we consider about the unit test practice and create new document for unit testing.

I think both ok for me. If you think the code quality of test code is important then I think maybe it is better to create it

Copy link
Contributor

Choose a reason for hiding this comment

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

well, so how about write the default value expressly in each test?

OK. Let's try it, but Not now

{
name: "set timeout failed with empty value",
args: args{
dur: "",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is not needed.

{
name: "set timeout failed with empty value",
args: args{
dur: "",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is not needed.

internal/net/http/client/option_test.go Show resolved Hide resolved
internal/net/http/client/option_test.go Show resolved Hide resolved
internal/net/http/client/option_test.go Show resolved Hide resolved
@vankichi
Copy link
Contributor

@vankichi I think it is better to write transport comparator in client_test not in option_test, so I changed client_test implementation

@kevindiu
umm...so, you have to show above implementation in your PR description at least and you had to communicate me and @hlts2 before implementation at first. But, it is not a critical problem.

@kevindiu kevindiu requested a review from hlts2 November 16, 2020 05:04
hlts2
hlts2 previously approved these changes Nov 18, 2020
vankichi
vankichi previously approved these changes Nov 18, 2020
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

@vankichi
Copy link
Contributor

/rebase
/format
/approve

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by vankichi for branch: test/net/http/client

@vdaas-ci
Copy link
Collaborator

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

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 vankichi.

@vankichi vankichi merged commit b045e86 into master Nov 18, 2020
@vankichi vankichi deleted the test/net/http/client branch November 18, 2020 08:53
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