feat: 添加测试服务及相关测试用例,重构 demo 服务逻辑

This commit is contained in:
Rogee
2025-09-15 18:37:02 +08:00
parent dd097e9aec
commit f0b7e0202c
4 changed files with 53 additions and 9 deletions

View File

@@ -63,11 +63,11 @@ func (d *demo) Foo(
file *multipart.FileHeader, file *multipart.FileHeader,
req *FooUploadReq, req *FooUploadReq,
) error { ) error {
_, err := services.Class.First(ctx) _, err := services.Test.Test(ctx)
if err != nil { if err != nil {
// / // /
appErr := errorx.Wrap(err). appErr := errorx.Wrap(err).
WithMsg("获取班级失败"). WithMsg("获取测试失败").
WithData(fiber.Map{"route": "/v1/test"}). WithData(fiber.Map{"route": "/v1/test"}).
WithParams("handler", "Test.Hello") WithParams("handler", "Test.Hello")
return appErr return appErr

View File

@@ -1,7 +0,0 @@
package services
import "go.ipao.vip/atom/opt"
func Provide(opts ...opt.Option) error {
return nil
}

View File

@@ -0,0 +1,10 @@
package services
import "context"
// @provider
type test struct{}
func (t *test) Test(ctx context.Context) (string, error) {
return "Test", nil
}

View File

@@ -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())
})
}