36 lines
786 B
Go
36 lines
786 B
Go
|
|
package routers
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestRoutesUseRESTModulePrefix(t *testing.T) {
|
||
|
|
gin.SetMode(gin.TestMode)
|
||
|
|
engine := gin.New()
|
||
|
|
Register("mgt", engine)
|
||
|
|
|
||
|
|
expected := map[string]bool{
|
||
|
|
"GET /rest/mgt/ping": false,
|
||
|
|
"POST /rest/mgt/login": false,
|
||
|
|
"POST /rest/mgt/user/create": false,
|
||
|
|
"POST /rest/mgt/app/fetch": false,
|
||
|
|
}
|
||
|
|
for _, route := range engine.Routes() {
|
||
|
|
key := route.Method + " " + route.Path
|
||
|
|
if _, ok := expected[key]; ok {
|
||
|
|
expected[key] = true
|
||
|
|
}
|
||
|
|
if route.Path == "/mgt" || strings.HasPrefix(route.Path, "/mgt/") {
|
||
|
|
t.Fatalf("legacy route remains registered: %s", route.Path)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for route, found := range expected {
|
||
|
|
if !found {
|
||
|
|
t.Errorf("route not registered: %s", route)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|