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

Implement internal/info/info test #862

Merged
merged 32 commits into from
Feb 19, 2021
Merged

Implement internal/info/info test #862

merged 32 commits into from
Feb 19, 2021

Conversation

kevindiu
Copy link
Contributor

@kevindiu kevindiu commented Nov 27, 2020

Description:

This PR implements internal/info/info test.
It refactors info.go to allow mocking the runtime.Caller and runtime.FuncForPC function to complete the test case.

grammar check passed

Because this PR includes refactoring, author review is required.

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

@codecov
Copy link

codecov bot commented Nov 27, 2020

Codecov Report

Merging #862 (a6f2b59) into master (d113363) will increase coverage by 0.15%.
The diff coverage is 89.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #862      +/-   ##
==========================================
+ Coverage   14.67%   14.82%   +0.15%     
==========================================
  Files         495      496       +1     
  Lines       28363    28337      -26     
==========================================
+ Hits         4161     4201      +40     
+ Misses      23953    23885      -68     
- Partials      249      251       +2     
Impacted Files Coverage Δ
internal/errors/info.go 0.00% <0.00%> (ø)
internal/info/info.go 92.96% <92.18%> (+62.96%) ⬆️
internal/info/option.go 100.00% <100.00%> (ø)
internal/errors/runner.go 0.00% <0.00%> (-100.00%) ⬇️
internal/errgroup/group.go 92.42% <0.00%> (-1.52%) ⬇️
internal/net/net.go
internal/worker/worker.go 83.33% <0.00%> (+1.04%) ⬆️

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 d113363...1c95c7f. Read the comment docs.

@kevindiu
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

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

@hlts2
Copy link
Contributor

hlts2 commented Nov 30, 2020

@kevindiu
Could you please fix failing test for TestDetail_Get??
https://github.com/vdaas/vald/pull/862/checks?check_run_id=1462354206#step:5:49

internal/info/info.go Outdated Show resolved Hide resolved
internal/info/info.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
hlts2
hlts2 previously approved these changes Dec 1, 2020
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
internal/info/info_test.go Outdated Show resolved Hide resolved
@kevindiu kevindiu changed the title Implement internal/info/info test [WIP] Implement internal/info/info test Dec 2, 2020
@github-actions github-actions bot added size/XXL and removed size/XL labels Dec 8, 2020
@kevindiu kevindiu changed the title [WIP] Implement internal/info/info test Implement internal/info/info test Dec 15, 2020
@kevindiu kevindiu requested a review from hlts2 December 15, 2020 05:11
@kevindiu
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

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

@kevindiu
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

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

Comment on lines 93 to 114
func Init(name string) {
once.Do(func() {
infoProvider, _ = New(WithServerName(name))
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hlts2 should we return the error in this function?

Suggested change
func Init(name string) {
once.Do(func() {
infoProvider, _ = New(WithServerName(name))
})
}
func Init(name string) error {
ip, err = New(WithServerName(name))
if err != nil {
return err
}
once.Do(func() {
infoProvider = ip
})
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmmm.. 🤔
I agree with your opinion.
but if you fix it, the interface will change, so it may be necessary to discuss it at first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes I think so. what do you think?
@vankichi @hlts2

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 would be better retuning the error.
when you apply this implementation, how this change will affect another current implementations?

Copy link
Contributor Author

@kevindiu kevindiu Dec 21, 2020

Choose a reason for hiding this comment

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

@vankichi @hlts2
changes of this function will cause the refactoring on 1 another file.
https://github.com/vdaas/vald/search?q=%22info.init%22

The image of the changes is like this, and this changes will cause all of the vald component not be able started if the name is not set. Or we can only log the error without returning the error here?

	if err := info.Init(r.name); err != nil {
               // maybe log the error only? 
               return 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 think the Init() functions should not return error, same as the current implementation of master branch.
If the New() error functions returns some error inside the Init() function, it means the arguments passed in Init() function is invalid = it means there're bugs in our codes. So it is better to use log.Fatal like the following:

func Init(name string) error {
        ip, err = New(WithServerName(name)) // the passed arguments of the New function is just controlled by our code here!
        if err != nil {
            log.Fatal("info.Init failed")
        }

The behavior of the Init() function cannot be controlled by the config.yaml, I think it is okay to panic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rinx I am not sure if your suggestion works, because the logger log.Init() is executed after the info is initialized.

if err := info.Init(r.name); err != nil {
return err
}
p, isHelp, err := params.New(
params.WithConfigFileDescription(fmt.Sprintf("%s config file path", r.name)),
).Parse()
if isHelp || err != nil {
log.Init(log.WithLevel(level.FATAL.String()))

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rinx what do you think about this changes?
237248d
cc: @kpango

Copy link
Contributor

Choose a reason for hiding this comment

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

good 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you :)

@vdaas-ci
Copy link
Collaborator

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

Copy link
Collaborator

@kpango kpango left a comment

Choose a reason for hiding this comment

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

LGTM

@kpango kpango merged commit 878059d into master Feb 19, 2021
@kpango kpango deleted the test/internal/info branch February 19, 2021 01:05
@vdaas-ci vdaas-ci mentioned this pull request Feb 19, 2021
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.

None yet

6 participants