Skip to content

Fix toolregistrytest by using fake #5627

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

Merged
merged 5 commits into from
Mar 6, 2025
Merged

Conversation

ffjlabo
Copy link
Member

@ffjlabo ffjlabo commented Mar 6, 2025

What this PR does:

as title

Why we need it:

It is better to use the same type in both the cases used in actual logic and test like zaptest.
https://github.com/uber-go/zap/blob/master/zaptest/logger.go#L77

The users don't need to define an additional interface to replace the tool registry on the test.

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

ffjlabo added 4 commits March 6, 2025 09:46
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
Copy link

codecov bot commented Mar 6, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 8 lines in your changes missing coverage. Please review.

Project coverage is 26.57%. Comparing base (a252de8) to head (1d8bea3).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../toolregistry/toolregistrytest/toolregistrytest.go 71.42% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5627      +/-   ##
==========================================
+ Coverage   26.54%   26.57%   +0.02%     
==========================================
  Files         477      477              
  Lines       50666    50644      -22     
==========================================
+ Hits        13450    13458       +8     
+ Misses      36153    36128      -25     
+ Partials     1063     1058       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ffjlabo ffjlabo marked this pull request as ready for review March 6, 2025 01:19
@ffjlabo ffjlabo enabled auto-merge (squash) March 6, 2025 01:20
func (r *ToolRegistry) newTmpDir() (string, error) {
return os.MkdirTemp(r.tmpDir, "")
type fakeClient struct {
pipedservicetest.MockPluginServiceClient
Copy link
Member Author

Choose a reason for hiding this comment

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

Use it to reduce the cost of maintaining fake implementation.

Copy link
Member

Choose a reason for hiding this comment

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

[IMO]
Using gomock only for this embedding is a bit complex.
How about embedding service.PluginServiceClient instead of generated mock?

type PluginServiceClient interface {

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, sounds good!
I thought we needed the actual instance to override the specific method. 🙏
It works fine.

1d8bea3

Copy link
Member

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

I agree to use fake in the toolregistrytest.
I commented on how we prepare the fake.

func (r *ToolRegistry) newTmpDir() (string, error) {
return os.MkdirTemp(r.tmpDir, "")
type fakeClient struct {
pipedservicetest.MockPluginServiceClient
Copy link
Member

Choose a reason for hiding this comment

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

[IMO]
Using gomock only for this embedding is a bit complex.
How about embedding service.PluginServiceClient instead of generated mock?

type PluginServiceClient interface {

@github-actions github-actions bot removed the area/tool label Mar 6, 2025
@ffjlabo ffjlabo requested a review from Warashi March 6, 2025 01:44
Copy link
Member

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

Nice 👍

@ffjlabo ffjlabo merged commit 0137126 into master Mar 6, 2025
18 checks passed
@ffjlabo ffjlabo deleted the fix-toolregistrytest-as-fake branch March 6, 2025 02:14
@github-actions github-actions bot mentioned this pull request Mar 25, 2025
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.

3 participants