2026-07-27 01:11:38 +08:00
|
|
|
package routers
|
|
|
|
|
|
|
|
|
|
import (
|
2026-07-27 02:03:26 +08:00
|
|
|
"net/http"
|
2026-07-27 01:11:38 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestPlatformGasRouteUsesGasBasic(t *testing.T) {
|
|
|
|
|
engine := gin.New()
|
|
|
|
|
RegisterPlatform("heqi", engine)
|
|
|
|
|
|
|
|
|
|
for _, route := range engine.Routes() {
|
|
|
|
|
if route.Path == "/heqi/platform/v1/gas/gas_station" {
|
|
|
|
|
t.Fatal("gas station route must use gas_basic as its resource name")
|
|
|
|
|
}
|
|
|
|
|
if route.Method == "GET" && route.Path == "/heqi/platform/v1/gas/gas_basic" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
t.Fatal("gas_basic list route is not registered")
|
|
|
|
|
}
|
2026-07-27 02:03:26 +08:00
|
|
|
|
|
|
|
|
func TestPlatformOrganizationAndAccountRoutesExposeResourceCRUD(t *testing.T) {
|
|
|
|
|
engine := gin.New()
|
|
|
|
|
RegisterPlatform("heqi", engine)
|
|
|
|
|
|
|
|
|
|
routes := make(map[string]map[string]bool)
|
|
|
|
|
for _, route := range engine.Routes() {
|
|
|
|
|
if routes[route.Path] == nil {
|
|
|
|
|
routes[route.Path] = make(map[string]bool)
|
|
|
|
|
}
|
|
|
|
|
routes[route.Path][route.Method] = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, resource := range []string{
|
|
|
|
|
"/gas/gas_basic",
|
|
|
|
|
"/gas/gas_account",
|
|
|
|
|
"/delivery/delivery_basic",
|
|
|
|
|
"/delivery/delivery_account",
|
|
|
|
|
"/staff/account",
|
|
|
|
|
"/staff/credential",
|
|
|
|
|
"/user/account",
|
|
|
|
|
"/user/address",
|
|
|
|
|
"/user/service_relation",
|
|
|
|
|
"/platform/platfrom_account",
|
|
|
|
|
"/platform/platform_role",
|
|
|
|
|
"/platform/platform_menu",
|
|
|
|
|
} {
|
|
|
|
|
assertRouteMethods(t, routes, "/heqi/platform/v1"+resource, http.MethodGet, http.MethodPost)
|
|
|
|
|
assertRouteMethods(t, routes, "/heqi/platform/v1"+resource+"/:identity", http.MethodGet, http.MethodPut, http.MethodDelete)
|
|
|
|
|
assertRouteMethods(t, routes, "/heqi/platform/v1"+resource+"/:identity/status", http.MethodPatch)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assertRouteMethods(t, routes, "/heqi/platform/v1/platform/platform_role/:identity/menus", http.MethodPut)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func assertRouteMethods(t *testing.T, routes map[string]map[string]bool, path string, methods ...string) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
for _, method := range methods {
|
|
|
|
|
if !routes[path][method] {
|
|
|
|
|
t.Errorf("route %s %s is not registered", method, path)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|