少提交的东西
This commit is contained in:
@@ -20,7 +20,7 @@ import (
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
accountService "github.com/break/junhong_cmp_fiber/internal/service/account"
|
||||
@@ -108,9 +108,9 @@ func setupRegressionTestEnv(t *testing.T) *regressionTestEnv {
|
||||
permSvc := permissionService.New(permStore)
|
||||
|
||||
// 初始化所有 Handler
|
||||
accountHandler := handler.NewAccountHandler(accService)
|
||||
roleHandler := handler.NewRoleHandler(roleSvc)
|
||||
permHandler := handler.NewPermissionHandler(permSvc)
|
||||
accountHandler := admin.NewAccountHandler(accService)
|
||||
roleHandler := admin.NewRoleHandler(roleSvc)
|
||||
permHandler := admin.NewPermissionHandler(permSvc)
|
||||
|
||||
// 创建 Fiber App
|
||||
app := fiber.New(fiber.Config{
|
||||
@@ -168,17 +168,17 @@ func TestAPIRegression_AllEndpointsAccessible(t *testing.T) {
|
||||
{"GET", "/health/ready", "Readiness check"},
|
||||
|
||||
// Account endpoints
|
||||
{"GET", "/api/v1/accounts", "List accounts"},
|
||||
{"GET", "/api/v1/accounts/1", "Get account"},
|
||||
{"GET", "/api/admin/accounts", "List accounts"},
|
||||
{"GET", "/api/admin/accounts/1", "Get account"},
|
||||
|
||||
// Role endpoints
|
||||
{"GET", "/api/v1/roles", "List roles"},
|
||||
{"GET", "/api/v1/roles/1", "Get role"},
|
||||
{"GET", "/api/admin/roles", "List roles"},
|
||||
{"GET", "/api/admin/roles/1", "Get role"},
|
||||
|
||||
// Permission endpoints
|
||||
{"GET", "/api/v1/permissions", "List permissions"},
|
||||
{"GET", "/api/v1/permissions/1", "Get permission"},
|
||||
{"GET", "/api/v1/permissions/tree", "Get permission tree"},
|
||||
{"GET", "/api/admin/permissions", "List permissions"},
|
||||
{"GET", "/api/admin/permissions/1", "Get permission"},
|
||||
{"GET", "/api/admin/permissions/tree", "Get permission tree"},
|
||||
}
|
||||
|
||||
for _, ep := range endpoints {
|
||||
@@ -214,13 +214,13 @@ func TestAPIRegression_RouteModularization(t *testing.T) {
|
||||
env.db.Create(account)
|
||||
|
||||
// 测试获取账号
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/accounts/%d", account.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/accounts/%d", account.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
// 测试获取角色列表
|
||||
req = httptest.NewRequest("GET", fmt.Sprintf("/api/v1/accounts/%d/roles", account.ID), nil)
|
||||
req = httptest.NewRequest("GET", fmt.Sprintf("/api/admin/accounts/%d/roles", account.ID), nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -236,13 +236,13 @@ func TestAPIRegression_RouteModularization(t *testing.T) {
|
||||
env.db.Create(role)
|
||||
|
||||
// 测试获取角色
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/roles/%d", role.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/roles/%d", role.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
// 测试获取权限列表
|
||||
req = httptest.NewRequest("GET", fmt.Sprintf("/api/v1/roles/%d/permissions", role.ID), nil)
|
||||
req = httptest.NewRequest("GET", fmt.Sprintf("/api/admin/roles/%d/permissions", role.ID), nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -259,13 +259,13 @@ func TestAPIRegression_RouteModularization(t *testing.T) {
|
||||
env.db.Create(perm)
|
||||
|
||||
// 测试获取权限
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/permissions/%d", perm.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/permissions/%d", perm.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
// 测试获取权限树
|
||||
req = httptest.NewRequest("GET", "/api/v1/permissions/tree", nil)
|
||||
req = httptest.NewRequest("GET", "/api/admin/permissions/tree", nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -280,20 +280,20 @@ func TestAPIRegression_ErrorHandling(t *testing.T) {
|
||||
|
||||
t.Run("资源不存在返回正确错误码", func(t *testing.T) {
|
||||
// 账号不存在
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts/99999", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts/99999", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
// 应该返回业务错误,不是 404
|
||||
assert.NotEqual(t, fiber.StatusNotFound, resp.StatusCode)
|
||||
|
||||
// 角色不存在
|
||||
req = httptest.NewRequest("GET", "/api/v1/roles/99999", nil)
|
||||
req = httptest.NewRequest("GET", "/api/admin/roles/99999", nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, fiber.StatusNotFound, resp.StatusCode)
|
||||
|
||||
// 权限不存在
|
||||
req = httptest.NewRequest("GET", "/api/v1/permissions/99999", nil)
|
||||
req = httptest.NewRequest("GET", "/api/admin/permissions/99999", nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, fiber.StatusNotFound, resp.StatusCode)
|
||||
@@ -301,7 +301,7 @@ func TestAPIRegression_ErrorHandling(t *testing.T) {
|
||||
|
||||
t.Run("无效参数返回正确错误码", func(t *testing.T) {
|
||||
// 无效账号 ID
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts/invalid", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts/invalid", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, fiber.StatusInternalServerError, resp.StatusCode)
|
||||
@@ -328,20 +328,20 @@ func TestAPIRegression_Pagination(t *testing.T) {
|
||||
|
||||
t.Run("分页参数正常工作", func(t *testing.T) {
|
||||
// 第一页
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts?page=1&page_size=10", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts?page=1&page_size=10", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
// 第二页
|
||||
req = httptest.NewRequest("GET", "/api/v1/accounts?page=2&page_size=10", nil)
|
||||
req = httptest.NewRequest("GET", "/api/admin/accounts?page=2&page_size=10", nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("默认分页参数工作", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -355,7 +355,7 @@ func TestAPIRegression_ResponseFormat(t *testing.T) {
|
||||
defer env.redisCleanup()
|
||||
|
||||
t.Run("成功响应包含正确字段", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -382,9 +382,9 @@ func TestAPIRegression_ServicesIntegration(t *testing.T) {
|
||||
// 验证所有模块路由都已注册
|
||||
endpoints := []string{
|
||||
"/health",
|
||||
"/api/v1/accounts",
|
||||
"/api/v1/roles",
|
||||
"/api/v1/permissions",
|
||||
"/api/admin/accounts",
|
||||
"/api/admin/roles",
|
||||
"/api/admin/permissions",
|
||||
}
|
||||
|
||||
for _, ep := range endpoints {
|
||||
|
||||
Reference in New Issue
Block a user