Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ginmill.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func NewFeatures(routes gin.RoutesInfo) *Features {
return f
}

// GetRoutes is a getter for RoutesInfo
func (f *Features) GetRoutes() gin.RoutesInfo {
r := make(gin.RoutesInfo, len(f.routes))
copy(r, f.routes)
return r

}

// With pre-defined Features for ginmill
func (s *Server) With(f *Features) *Server {
for _, r := range f.routes {
Expand Down
22 changes: 22 additions & 0 deletions ginmill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ func TestNewFeatures(t *testing.T) {
}
}

func TestFeatures_GetRoutes(t *testing.T) {
r := routes()
f := NewFeatures(r)
got := f.GetRoutes()

if len(got) != len(f.routes) {
t.Errorf("GetRoutes() length = %d, want %d", len(got), len(f.routes))
}

for i := range got {
if got[i].Method != f.routes[i].Method || got[i].Path != f.routes[i].Path {
t.Errorf("GetRoutes() element %d not equal", i)
}
}

if len(got) > 0 {
got[0].Path = "/changed"
if got[0].Path == f.routes[0].Path {
t.Errorf("GetRoutes should return a copy, not a reference")
}
}
}

func TestServer_With(t *testing.T) {
type args struct {
Expand Down