From f0b7e0202c31fa8049cb04ee60baf8e8ee2887db Mon Sep 17 00:00:00 2001 From: Rogee Date: Mon, 15 Sep 2025 18:37:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=8F=8A=E7=9B=B8=E5=85=B3=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=EF=BC=8C=E9=87=8D=E6=9E=84=20demo=20?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/project/app/http/v1/demo.go.tpl | 4 +- templates/project/app/services/demo.go.tpl | 7 ---- templates/project/app/services/test.go.tpl | 10 +++++ .../project/app/services/test_test.go.tpl | 41 +++++++++++++++++++ 4 files changed, 53 insertions(+), 9 deletions(-) delete mode 100644 templates/project/app/services/demo.go.tpl create mode 100644 templates/project/app/services/test.go.tpl create mode 100644 templates/project/app/services/test_test.go.tpl diff --git a/templates/project/app/http/v1/demo.go.tpl b/templates/project/app/http/v1/demo.go.tpl index db49dc2..4b97022 100644 --- a/templates/project/app/http/v1/demo.go.tpl +++ b/templates/project/app/http/v1/demo.go.tpl @@ -63,11 +63,11 @@ func (d *demo) Foo( file *multipart.FileHeader, req *FooUploadReq, ) error { - _, err := services.Class.First(ctx) + _, err := services.Test.Test(ctx) if err != nil { // 示例:在控制器层自定义错误消息/附加数据 appErr := errorx.Wrap(err). - WithMsg("获取班级失败"). + WithMsg("获取测试失败"). WithData(fiber.Map{"route": "/v1/test"}). WithParams("handler", "Test.Hello") return appErr diff --git a/templates/project/app/services/demo.go.tpl b/templates/project/app/services/demo.go.tpl deleted file mode 100644 index 163a663..0000000 --- a/templates/project/app/services/demo.go.tpl +++ /dev/null @@ -1,7 +0,0 @@ -package services - -import "go.ipao.vip/atom/opt" - -func Provide(opts ...opt.Option) error { - return nil -} diff --git a/templates/project/app/services/test.go.tpl b/templates/project/app/services/test.go.tpl new file mode 100644 index 0000000..051d196 --- /dev/null +++ b/templates/project/app/services/test.go.tpl @@ -0,0 +1,10 @@ +package services + +import "context" + +// @provider +type test struct{} + +func (t *test) Test(ctx context.Context) (string, error) { + return "Test", nil +} diff --git a/templates/project/app/services/test_test.go.tpl b/templates/project/app/services/test_test.go.tpl new file mode 100644 index 0000000..0f82fb6 --- /dev/null +++ b/templates/project/app/services/test_test.go.tpl @@ -0,0 +1,41 @@ +package services + +import ( + "testing" + "time" + + "{{.ModuleName}}/app/commands/testx" + + . "github.com/smartystreets/goconvey/convey" + "github.com/stretchr/testify/suite" + + _ "go.ipao.vip/atom" + "go.ipao.vip/atom/contracts" + "go.uber.org/dig" +) + +type TestSuiteInjectParams struct { + dig.In + + Initials []contracts.Initial `group:"initials"` // nolint:structcheck +} + +type TestSuite struct { + suite.Suite + + TestSuiteInjectParams +} + +func Test_Test(t *testing.T) { + providers := testx.Default().With(Provide) + + testx.Serve(providers, t, func(p TestSuiteInjectParams) { + suite.Run(t, &TestSuite{TestSuiteInjectParams: p}) + }) +} + +func (t *TestSuite) Test_Test() { + Convey("test_work", t.T(), func() { + t.T().Log("start test at", time.Now()) + }) +}