jenkins
This commit is contained in:
@@ -36,7 +36,11 @@ func NewGinEngineWithRuntime(runtime *config.Store, access *systemservice.Access
|
||||
prefix = strings.TrimSuffix(snapshot.Admin.RouterPrefix, "/")
|
||||
}
|
||||
public := engine.Group(prefix)
|
||||
public.GET("/health", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") })
|
||||
health := func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }
|
||||
engine.GET("/health", health)
|
||||
if prefix != "" {
|
||||
public.GET("/health", health)
|
||||
}
|
||||
|
||||
private := engine.Group(prefix)
|
||||
// The reference administration behavior installs operation recording after JWT,
|
||||
@@ -103,11 +107,11 @@ func NewGinEngineWithRuntime(runtime *config.Store, access *systemservice.Access
|
||||
}
|
||||
}
|
||||
if ws != nil && ws.Enabled() {
|
||||
engine.GET(ws.Path(), handleWebSocket)
|
||||
engine.GET(websocketRoutePath(prefix, ws), handleWebSocket)
|
||||
}
|
||||
if logger != nil {
|
||||
logger.Info("websocket endpoint initialized", "mod", "websocket",
|
||||
"enabled", ws != nil && ws.Enabled(), "path", websocketPath(ws))
|
||||
"enabled", ws != nil && ws.Enabled(), "path", websocketRoutePath(prefix, ws))
|
||||
}
|
||||
env := ""
|
||||
if snapshot != nil && snapshot.Admin != nil && snapshot.Admin.App != nil {
|
||||
@@ -125,10 +129,6 @@ func NewGinEngineWithRuntime(runtime *config.Store, access *systemservice.Access
|
||||
}
|
||||
|
||||
engine.NoRoute(func(c *gin.Context) {
|
||||
if ws != nil && ws.Enabled() && c.Request.Method == http.MethodGet && c.Request.URL.Path == websocketRoutePath(prefix, ws) {
|
||||
handleWebSocket(c)
|
||||
return
|
||||
}
|
||||
if staticfiles.Serve(c, runtime) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -133,6 +133,17 @@ func TestSwaggerSupportsRouterPrefix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthEndpointKeepsRootProbePathWithRouterPrefix(t *testing.T) {
|
||||
engine := NewGinEngine(config.NewStore(&config.Config{Admin: &config.Admin{RouterPrefix: "/admin"}}), nil, emptyHandlers(), nil, nil, nil, nil, "test")
|
||||
for _, path := range []string{"/health", "/admin/health"} {
|
||||
response := httptest.NewRecorder()
|
||||
engine.ServeHTTP(response, httptest.NewRequest(http.MethodGet, path, nil))
|
||||
if response.Code != http.StatusOK || response.Body.String() != `"ok"` {
|
||||
t.Fatalf("health path %s status=%d body=%s", path, response.Code, response.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSwaggerUsesRootBasePathWithoutRouterPrefix(t *testing.T) {
|
||||
engine := NewGinEngine(config.NewStore(&config.Config{Admin: &config.Admin{}}), nil, emptyHandlers(), nil, nil, nil, nil, "v1.0.0")
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
@@ -102,6 +102,21 @@ func TestWebSocketRouteSupportsRouterPrefix(t *testing.T) {
|
||||
t.Fatal("prefixed websocket handshake returned nil connection")
|
||||
}
|
||||
_ = connection.Close()
|
||||
for _, route := range engine.Routes() {
|
||||
if route.Method == http.MethodGet && route.Path == "/ws" {
|
||||
t.Fatal("unprefixed websocket route should not be registered")
|
||||
}
|
||||
}
|
||||
found := false
|
||||
for _, route := range engine.Routes() {
|
||||
if route.Method == http.MethodGet && route.Path == "/admin/ws" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("prefixed websocket route was not registered")
|
||||
}
|
||||
}
|
||||
|
||||
var _ platformws.Hub = (*websocketintegration.Server)(nil)
|
||||
|
||||
Reference in New Issue
Block a user