mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 18:00:00 +08:00
fix(goctl): use rest.Serverless for generated integration tests (#5258)
This commit is contained in:
@@ -38,13 +38,9 @@ func TestServerIntegration(t *testing.T) {
|
|||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
handler.RegisterHandlers(server, ctx)
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
// Start server in background
|
// Create serverless wrapper for testing
|
||||||
go func() {
|
serverless, err := rest.NewServerless(server)
|
||||||
server.Start()
|
require.NoError(t, err)
|
||||||
}()
|
|
||||||
|
|
||||||
// Wait for server to start
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -56,7 +52,7 @@ func TestServerIntegration(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "health check",
|
name: "health check",
|
||||||
method: "GET",
|
method: http.MethodGet,
|
||||||
path: "/health",
|
path: "/health",
|
||||||
expectedStatus: http.StatusNotFound, // Adjust based on actual routes
|
expectedStatus: http.StatusNotFound, // Adjust based on actual routes
|
||||||
setup: func() {},
|
setup: func() {},
|
||||||
@@ -72,7 +68,7 @@ func TestServerIntegration(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{{end}}{{end}}{
|
{{end}}{{end}}{
|
||||||
name: "not found route",
|
name: "not found route",
|
||||||
method: "GET",
|
method: http.MethodGet,
|
||||||
path: "/nonexistent",
|
path: "/nonexistent",
|
||||||
expectedStatus: http.StatusNotFound,
|
expectedStatus: http.StatusNotFound,
|
||||||
setup: func() {},
|
setup: func() {},
|
||||||
@@ -87,7 +83,7 @@ func TestServerIntegration(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
server.ServeHTTP(rr, req)
|
serverless.Serve(rr, req)
|
||||||
|
|
||||||
assert.Equal(t, tt.expectedStatus, rr.Code)
|
assert.Equal(t, tt.expectedStatus, rr.Code)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user