Files
summercms/surf/routetable_coverage_test.go
Jakub Zych 98dd09847a test(06-05): close framework coverage gaps in bouncer, surf, wire, fetchguard
- Registry neither-interface, nil-registry, and authenticate default
- MemoryStore sweep actually drops expired entries
- RegisterHouseMiddlewareFactory duplicate-name failure
- pathScopedCORS unmatched path plus empty-raw-group introspection
- Time UnmarshalJSON +00:00/Z and PublicOnlyMode host/IP cases
2026-09-19 21:08:04 +02:00

84 lines
2.5 KiB
Go

package surf
import (
"net/http"
"strings"
"testing"
"git.golem15.com/golem15/summercms/pact"
)
// Gap (c): RegisterHouseMiddlewareFactory duplicate-name failure. The
// non-house RegisterMiddlewareFactory duplicate path is already covered
// by TestDuplicateMiddlewareFactoryNamesPluginAndName.
func TestDuplicateHouseMiddlewareFactoryNamesPluginAndName(t *testing.T) {
r := New(nil)
fn := func(string) pact.Middleware {
return func(next http.Handler) http.Handler { return next }
}
if err := r.RegisterHouseMiddlewareFactory("golem15.demo", "house.param", fn); err != nil {
t.Fatal(err)
}
err := r.RegisterHouseMiddlewareFactory("golem15.other", "house.param", fn)
if err == nil || !strings.Contains(err.Error(), "golem15.demo") || !strings.Contains(err.Error(), "house.param") {
t.Fatalf("want plugin and factory name in error, got %v", err)
}
}
func TestRegisterHouseMiddlewareFactoryEmptyName(t *testing.T) {
r := New(nil)
err := r.RegisterHouseMiddlewareFactory("golem15.demo", "", func(string) pact.Middleware {
return func(next http.Handler) http.Handler { return next }
})
if err == nil || !strings.Contains(err.Error(), "golem15.demo") {
t.Fatalf("empty factory name: %v", err)
}
}
// Gap (g): Router.Routes() on an empty router, and an empty raw group
// (zero routes). Raw:true is inspectable on the Group itself; Routes()
// only lists registered handlers, so an empty raw group produces no
// RouteInfo — that is structural, not a missing assertion.
func TestRoutesEmptyRouter(t *testing.T) {
r := New(nil)
got := r.Routes()
if got == nil {
t.Fatal("empty router Routes() must return a non-nil empty slice")
}
if len(got) != 0 {
t.Fatalf("empty router Routes() = %#v", got)
}
if (*Router)(nil).Routes() != nil {
t.Fatal("nil router Routes() must return nil")
}
}
func TestEmptyRawGroupRawFlagOnGroupNotRouteInfo(t *testing.T) {
r := New(nil)
var inner *Group
r.GroupRaw("/oauth", nil, func(g pact.Router) {
inner = g.(*Group)
})
if inner == nil || !inner.raw {
t.Fatal("empty GroupRaw must keep raw=true on Group")
}
if len(r.Routes()) != 0 {
t.Fatalf("empty raw group leaked RouteInfo: %v", r.Routes())
}
// Group.GroupRaw (nested) is a distinct method from Router.GroupRaw.
r.Group("/wrap", nil, func(g pact.Router) {
g.GroupRaw("/inner", nil, func(c pact.Router) {
inner = c.(*Group)
})
})
if inner == nil || !inner.raw {
t.Fatal("nested GroupRaw must be raw")
}
if len(r.Routes()) != 0 {
t.Fatalf("nested empty raw group leaked RouteInfo: %v", r.Routes())
}
}