test(goctl): add regression test for per-service type alias filtering (#5481)#5483
Merged
kevwan merged 2 commits intozeromicro:masterfrom Mar 15, 2026
Merged
Conversation
Verify that genCallGroup only emits type aliases for the request/response messages actually used by each service's RPCs, not all messages in the proto file (issue zeromicro#5481, fixed in zeromicro#5482).
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a unit test for tools/goctl/rpc/generator to validate multi-service RPC client generation behavior, specifically that generated call clients only type-alias protobuf message types used by each service (regression coverage for issue #5481).
Changes:
- Introduce
TestGenCallGroup_OnlyUsedTypesAliasedforgenCallGroupin multi-service mode. - Add a minimal
mockDirContextto drive generator output into a temp directory for assertions.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a focused unit test in the goctl RPC generator to validate multi-service client generation behavior: each generated call client should only alias protobuf message types actually used by that service’s RPCs (regression coverage for issue #5481).
Changes:
- Introduce
TestGenCallGroup_OnlyUsedTypesAliasedto assert per-service alias scoping in multi-service generation. - Add a minimal
DirContextmock and temporary filesystem setup to exercisegenCallGroupoutput.
Comment on lines
+40
to
+48
| func TestGenCallGroup_OnlyUsedTypesAliased(t *testing.T) { | ||
| tmpDir := t.TempDir() | ||
| callBase := filepath.Join(tmpDir, "call") | ||
| pbBase := filepath.Join(tmpDir, "pb") | ||
|
|
||
| // Pre-create subdirs that genCallGroup will write into. | ||
| require.NoError(t, os.MkdirAll(filepath.Join(callBase, "servicea"), 0755)) | ||
| require.NoError(t, os.MkdirAll(filepath.Join(callBase, "serviceb"), 0755)) | ||
| require.NoError(t, os.MkdirAll(pbBase, 0755)) |
Comment on lines
+56
to
+57
| // Return a package path whose Base() is the lowercase service name. | ||
| return filepath.Join(callBase, strings.ToLower(childPath)), nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
TestGenCallGroup_OnlyUsedTypesAliasedtotools/goctl/rpc/generator/gencall_test.goas a regression guard for #5481 (fixed in #5482).Why
The fix in #5482 was merged without a test. This test exercises
genCallGroupdirectly with two services that have completely disjoint message sets and asserts:servicea.gocontains aliases only forAReq/AResp(notBReq/BResp)serviceb.gocontains aliases only forBReq/BResp(notAReq/AResp)The test fails against the pre-fix code and passes with the fix, so it will catch any future regression.
How to verify