mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 00:40:00 +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:
60
tools/goctl/api/gogen/svc_test.tpl
Normal file
60
tools/goctl/api/gogen/svc_test.tpl
Normal file
@@ -0,0 +1,60 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl {{.version}}
|
||||
|
||||
package svc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"{{.projectPkg}}/internal/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewServiceContext(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config config.Config
|
||||
setup func() config.Config
|
||||
}{
|
||||
{
|
||||
name: "default config",
|
||||
setup: func() config.Config {
|
||||
return config.Config{}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid config",
|
||||
setup: func() config.Config {
|
||||
return config.Config{
|
||||
// TODO: Add valid config values here
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := tt.setup()
|
||||
svcCtx := NewServiceContext(c)
|
||||
|
||||
// Basic assertions
|
||||
require.NotNil(t, svcCtx)
|
||||
assert.Equal(t, c, svcCtx.Config)
|
||||
|
||||
// TODO: Add additional assertions for middleware and dependencies
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceContext_Initialization(t *testing.T) {
|
||||
c := config.Config{}
|
||||
svcCtx := NewServiceContext(c)
|
||||
|
||||
// Verify service context is properly initialized
|
||||
assert.NotNil(t, svcCtx)
|
||||
assert.Equal(t, c, svcCtx.Config)
|
||||
|
||||
// TODO: Add tests for middleware initialization if any
|
||||
// TODO: Add tests for external dependencies if any
|
||||
}
|
||||
Reference in New Issue
Block a user