mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 16:30:01 +08:00
Add complete test scaffolding support with --test flag for API projects (#5176)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: kevwan <1918356+kevwan@users.noreply.github.com>
This commit is contained in:
42
tools/goctl/api/gogen/genintegrationtest.go
Normal file
42
tools/goctl/api/gogen/genintegrationtest.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package gogen
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/config"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/format"
|
||||
)
|
||||
|
||||
//go:embed integration_test.tpl
|
||||
var integrationTestTemplate string
|
||||
|
||||
func genIntegrationTest(dir, rootPkg, projectPkg string, cfg *config.Config, api *spec.ApiSpec) error {
|
||||
serviceName := api.Service.Name
|
||||
if len(serviceName) == 0 {
|
||||
serviceName = "server"
|
||||
}
|
||||
|
||||
filename, err := format.FileNamingFormat(cfg.NamingFormat, serviceName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return genFile(fileGenConfig{
|
||||
dir: dir,
|
||||
subdir: "",
|
||||
filename: filename + "_test.go",
|
||||
templateName: "integrationTestTemplate",
|
||||
category: category,
|
||||
templateFile: integrationTestTemplateFile,
|
||||
builtinTemplate: integrationTestTemplate,
|
||||
data: map[string]any{
|
||||
"projectPkg": projectPkg,
|
||||
"serviceName": serviceName,
|
||||
"version": version.BuildVersion,
|
||||
"hasRoutes": len(api.Service.Routes()) > 0,
|
||||
"routes": api.Service.Routes(),
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user