Skip to content

test(goctl): add regression test for per-service type alias filtering (#5481)#5483

Merged
kevwan merged 2 commits intozeromicro:masterfrom
kevwan:test/gencall-alias-filter
Mar 15, 2026
Merged

test(goctl): add regression test for per-service type alias filtering (#5481)#5483
kevwan merged 2 commits intozeromicro:masterfrom
kevwan:test/gencall-alias-filter

Conversation

@kevwan
Copy link
Contributor

@kevwan kevwan commented Mar 15, 2026

What

Adds TestGenCallGroup_OnlyUsedTypesAliased to tools/goctl/rpc/generator/gencall_test.go as a regression guard for #5481 (fixed in #5482).

Why

The fix in #5482 was merged without a test. This test exercises genCallGroup directly with two services that have completely disjoint message sets and asserts:

  • servicea.go contains aliases only for AReq/AResp (not BReq/BResp)
  • serviceb.go contains aliases only for BReq/BResp (not AReq/AResp)

The test fails against the pre-fix code and passes with the fix, so it will catch any future regression.

How to verify

cd tools/goctl
go test ./rpc/generator/... -run TestGenCallGroup_OnlyUsedTypesAliased -v

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).
Copilot AI review requested due to automatic review settings March 15, 2026 14:25
@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_OnlyUsedTypesAliased for genCallGroup in multi-service mode.
  • Add a minimal mockDirContext to drive generator output into a temp directory for assertions.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_OnlyUsedTypesAliased to assert per-service alias scoping in multi-service generation.
  • Add a minimal DirContext mock and temporary filesystem setup to exercise genCallGroup output.

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
@kevwan kevwan merged commit 567087a into zeromicro:master Mar 15, 2026
9 checks passed
@kevwan kevwan deleted the test/gencall-alias-filter branch March 15, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants