cmd/gf: test gen ctrl comments (#3575)

This commit is contained in:
Charles
2024-05-27 20:42:26 +08:00
committed by GitHub
parent 8f4d5f7d74
commit 9e9e42b45c
3 changed files with 77 additions and 0 deletions

View File

@ -307,3 +307,41 @@ func expectFilesContent(t *gtest.T, paths []string, expectPaths []string) {
t.Assert(val, expect)
}
}
// https://github.com/gogf/gf/issues/3569
func Test_Gen_Ctrl_Comments_Issue3569(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
var (
ctrlPath = gfile.Temp(guid.S())
apiFolder = gtest.DataPath("issue", "3569", "api")
in = genctrl.CGenCtrlInput{
SrcFolder: apiFolder,
DstFolder: ctrlPath,
WatchFile: "",
SdkPath: "",
SdkStdVersion: false,
SdkNoV1: false,
Clear: false,
Merge: true,
}
)
err := gutil.FillStructWithDefault(&in)
t.AssertNil(err)
err = gfile.Mkdir(ctrlPath)
t.AssertNil(err)
defer gfile.Remove(ctrlPath)
_, err = genctrl.CGenCtrl{}.Ctrl(ctx, in)
t.AssertNil(err)
//apiInterface file
var (
genApi = apiFolder + filepath.FromSlash("/hello/hello.go")
genApiExpect = apiFolder + filepath.FromSlash("/hello/hello_expect.go")
)
defer gfile.Remove(genApi)
t.Assert(gfile.GetContents(genApi), gfile.GetContents(genApiExpect))
})
}

View File

@ -0,0 +1,15 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package hello
import (
"context"
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/testdata/issue/3569/api/hello/v1"
)
type IHelloV1 interface {
Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error)
}

View File

@ -0,0 +1,24 @@
package v1
import "github.com/gogf/gf/v2/frame/g"
type HelloReq struct {
g.Meta `path:"/hello" tags:"Hello" method:"get" summary:"api-Hello"`
}
type HelloRes struct {
g.Meta `mime:"text/html" example:"string"`
}
// type Hello2Req struct {
// g.Meta `path:"/hello2" tags:"Hello" method:"get" summary:"api-Hello2"`
// }
// type Hello2Res struct {
// g.Meta `mime:"text/html" example:"string"`
// }
//type Hello3Req struct {
// g.Meta `path:"/hello3" tags:"Hello" method:"get" summary:"api-Hello3"`
// PodState consts.PodPhase
//}
//type Hello3Res struct {
//}