-
Notifications
You must be signed in to change notification settings - Fork 77
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
Conversation
[CHATOPS:HELP] ChatOps commands.
|
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
/rebase |
[REBASE] Rebase triggered by kevindiu for branch: test/internal/info |
@kevindiu |
/rebase |
[REBASE] Rebase triggered by kevindiu for branch: test/internal/info |
9f55bd3
to
bd90c25
Compare
/rebase |
[REBASE] Rebase triggered by kevindiu for branch: test/internal/info |
bd90c25
to
9495f9b
Compare
internal/info/info.go
Outdated
func Init(name string) { | ||
once.Do(func() { | ||
infoProvider, _ = New(WithServerName(name)) | ||
}) | ||
} |
There was a problem hiding this comment.
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?
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 | |
}) | |
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
vald/internal/runner/runner.go
Lines 65 to 74 in b54d583
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you :)
Co-authored-by: Hiroto Funakoshi <[email protected]>
Signed-off-by: kevindiu <[email protected]>
Signed-off-by: kevindiu <[email protected]>
Signed-off-by: vdaas-ci <[email protected]>
Co-authored-by: Hiroto Funakoshi <[email protected]>
Signed-off-by: kevindiu <[email protected]>
3e7b3bb
to
c3e9328
Compare
[FORMAT] Updating license headers and formatting go codes triggered by kevindiu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description:
This PR implements internal/info/info test.
It refactors info.go to allow mocking the
runtime.Caller
andruntime.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:
Types of changes:
Changes to Core Features:
Checklist: