优化结构
This commit is contained in:
@@ -97,6 +97,9 @@ func (r *Runtime) RegisterRoutes(public, private *gin.RouterGroup, engine *gin.E
|
||||
return
|
||||
}
|
||||
for _, registrar := range r.routes {
|
||||
if registrar == nil {
|
||||
continue
|
||||
}
|
||||
registrar.RegisterRoutes(public, private, engine)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"kra/pkg/database/migration"
|
||||
"kra/pkg/task"
|
||||
)
|
||||
@@ -41,3 +42,18 @@ func TestCatalogCollectsContributions(t *testing.T) {
|
||||
t.Fatalf("unexpected task methods: %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
type routeRegistrarStub struct{ called bool }
|
||||
|
||||
func (stub *routeRegistrarStub) RegisterRoutes(*gin.RouterGroup, *gin.RouterGroup, *gin.Engine) {
|
||||
stub.called = true
|
||||
}
|
||||
|
||||
func TestRuntimeSkipsNilRouteRegistrars(t *testing.T) {
|
||||
stub := &routeRegistrarStub{}
|
||||
runtime := NewRuntime(nil, stub)
|
||||
runtime.RegisterRoutes(nil, nil, nil)
|
||||
if !stub.called {
|
||||
t.Fatal("non-nil route registrar was not called")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user