From 2d3a4955da47906c41c13042a09ac5332502983f Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Sun, 17 May 2026 10:55:10 +0900 Subject: [PATCH] Fix apipkg lookup in GenerateExample of testing plugin --- testing/generate.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/testing/generate.go b/testing/generate.go index b134af8b7..801f74036 100644 --- a/testing/generate.go +++ b/testing/generate.go @@ -1,8 +1,6 @@ package testing import ( - "strings" - "goa.design/goa/v3/codegen" "goa.design/goa/v3/codegen/service" "goa.design/goa/v3/eval" @@ -52,9 +50,25 @@ func GenerateExample(genpkg string, roots []eval.Root, files []*codegen.File) ([ continue } for _, svc := range r.Services { - // Derive example implementation package name deterministically like Goa example generator - snake := codegen.SnakeCase(svc.Name) - apipkg := strings.ReplaceAll(snake, "_", "") + "api" + // Get example implementation package name from actual file header + var apipkg string + for _, f := range files { + for _, section := range f.Section("source-header") { + header, ok := section.Data.(map[string]any) + if !ok { + continue + } + p, ok := header["Pkg"].(string) + if !ok { + continue + } + apipkg = p + break + } + if apipkg != "" { + break + } + } if f := testcodegen.GenerateSuiteTopLevel(genpkg, apipkg, r, svc); f != nil { files = append(files, f) }