Skip to content

Fix apipkg lookup in GenerateExample of testing plugin#256

Open
tchssk wants to merge 1 commit into
v3from
testing-generateexample-apipkg
Open

Fix apipkg lookup in GenerateExample of testing plugin#256
tchssk wants to merge 1 commit into
v3from
testing-generateexample-apipkg

Conversation

@tchssk
Copy link
Copy Markdown
Member

@tchssk tchssk commented May 17, 2026

This pull request updates the logic in the testing/generate.go file to improve how the example implementation package name is determined when generating test suites. Instead of deriving the package name using string manipulation, the code now extracts it directly from the file header metadata, making the process more robust and accurate.

Improvements to package name determination:

  • Changed the method for determining the example implementation package name in GenerateExample to extract it from the file header's Pkg field, rather than constructing it from the service name using string manipulation.

Code cleanup:

  • Removed the unnecessary import of the strings package from testing/generate.go.

@tchssk tchssk marked this pull request as ready for review May 17, 2026 03:23
@raphael
Copy link
Copy Markdown
Member

raphael commented May 18, 2026

Nice, I like the direction here. Reading the package from generated metadata is a lot nicer than reconstructing it from the service name.

One case I think we still need to handle: files only has the files generated during this goa example run. If the example service implementation already exists, Goa skips emitting <service>.go, so this loop can end up grabbing the package from some other generated file, like main or interceptors. Then the root suite file would be generated with the wrong package on reruns or when adding the testing plugin to an existing example project.

Could we either keep using the same API package derivation Goa uses for the top-level service implementation, or make this lookup target that specific top-level service file and handle the already-exists case explicitly? A small test for the existing-service-file/rerun case would be great too.

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