更新依赖和调整目录结构,未修改模块
This commit is contained in:
62
pkgs/ecmall/internal/service/service_test.go
Normal file
62
pkgs/ecmall/internal/service/service_test.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"bsm/full/pkgs/ecmall/internal/config"
|
||||
ecmallserver "bsm/full/pkgs/ecmall/internal/server"
|
||||
)
|
||||
|
||||
// TestExposeRegistersPlatformModules guards the aggregate registry: the
|
||||
// platform modules (ads, cms, feedback, fts, logs, mgt) must contribute their
|
||||
// gRPC services and their native REST routes through service.Expose, and the
|
||||
// gRPC-only modules must keep contributing theirs.
|
||||
func TestExposeRegistersPlatformModules(t *testing.T) {
|
||||
t.Setenv("BSM_SERVICES", "")
|
||||
config.Spec.Services = []string{"all"}
|
||||
|
||||
srv, err := ecmallserver.New("0123456789abcdef0123456789abcdef", 3600, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("new server: %v", err)
|
||||
}
|
||||
if err := Expose(srv); err != nil {
|
||||
t.Fatalf("expose: %v", err)
|
||||
}
|
||||
|
||||
services := make(map[string]bool)
|
||||
for name := range srv.GRPC.GetServiceInfo() {
|
||||
services[name] = true
|
||||
}
|
||||
for _, prefix := range []string{"ads.", "cms.", "feedback.", "address.", "mall.", "market.", "order.", "passport.", "sender.", "wallet.", "initial."} {
|
||||
if !hasPrefix(services, prefix) {
|
||||
t.Errorf("gRPC service with prefix %q is not registered", prefix)
|
||||
}
|
||||
}
|
||||
|
||||
routes := make(map[string]bool)
|
||||
for _, route := range srv.HTTP.Routes() {
|
||||
routes[route.Method+" "+route.Path] = true
|
||||
}
|
||||
for _, path := range []string{
|
||||
"GET /rest/fts/ping",
|
||||
"GET /rest/fts/config",
|
||||
"POST /rest/fts/uploader",
|
||||
"GET /rest/logs/ping",
|
||||
"GET /rest/mgt/ping",
|
||||
"POST /rest/mgt/login",
|
||||
} {
|
||||
if !routes[path] {
|
||||
t.Errorf("native REST route %q is not registered", path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hasPrefix(names map[string]bool, prefix string) bool {
|
||||
for name := range names {
|
||||
if strings.HasPrefix(name, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user