From 2d3a4955da47906c41c13042a09ac5332502983f Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Sun, 17 May 2026 10:55:10 +0900 Subject: [PATCH 1/2] 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) } From 880c32181b1c1c9c814edeef2836bb279c37c5bd Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Sun, 24 May 2026 15:56:30 +0900 Subject: [PATCH 2/2] Fix apipkg lookup like Goa core --- testing/generate.go | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/testing/generate.go b/testing/generate.go index 801f74036..5a4ca09c8 100644 --- a/testing/generate.go +++ b/testing/generate.go @@ -1,6 +1,8 @@ package testing import ( + "strings" + "goa.design/goa/v3/codegen" "goa.design/goa/v3/codegen/service" "goa.design/goa/v3/eval" @@ -49,26 +51,17 @@ func GenerateExample(genpkg string, roots []eval.Root, files []*codegen.File) ([ if !ok { continue } + services := service.NewServicesData(r) + scope := codegen.NewNameScope() for _, svc := range r.Services { - // 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 - } + s := services.Get(svc.Name) + if s == nil { + continue } + scope.Unique(s.PkgName) + } + apipkg := scope.Unique(strings.ToLower(codegen.Goify(r.API.Name, false)), "api") + for _, svc := range r.Services { if f := testcodegen.GenerateSuiteTopLevel(genpkg, apipkg, r, svc); f != nil { files = append(files, f) }