MCPcopy
hub / github.com/pocketbase/pocketbase / TestRouterUnbind

Function TestRouterUnbind

tools/router/router_test.go:120–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestRouterUnbind(t *testing.T) {
121 calls := ""
122
123 r := router.NewRouter(func(w http.ResponseWriter, r *http.Request) (*router.Event, router.EventCleanupFunc) {
124 return &router.Event{
125 Response: w,
126 Request: r,
127 },
128 func() {
129 calls += ":cleanup"
130 }
131 })
132 r.Bind(&hook.Handler[*router.Event]{
133 Id: "root_1",
134 Func: func(e *router.Event) error {
135 calls += "root_1:"
136 return e.Next()
137 },
138 })
139 r.Bind(&hook.Handler[*router.Event]{
140 Id: "root_2",
141 Func: func(e *router.Event) error {
142 calls += "root_2:"
143 return e.Next()
144 },
145 })
146 r.Bind(&hook.Handler[*router.Event]{
147 Id: "root_3",
148 Func: func(e *router.Event) error {
149 calls += "root_3:"
150 return e.Next()
151 },
152 })
153 r.GET("/action", func(e *router.Event) error {
154 calls += "root_action"
155 return nil
156 }).Unbind("root_1")
157
158 ga := r.Group("/group_a")
159 ga.Unbind("root_1")
160 ga.Bind(&hook.Handler[*router.Event]{
161 Id: "group_a_1",
162 Func: func(e *router.Event) error {
163 calls += "group_a_1:"
164 return e.Next()
165 },
166 })
167 ga.Bind(&hook.Handler[*router.Event]{
168 Id: "group_a_2",
169 Func: func(e *router.Event) error {
170 calls += "group_a_2:"
171 return e.Next()
172 },
173 })
174 ga.Bind(&hook.Handler[*router.Event]{
175 Id: "group_a_3",
176 Func: func(e *router.Event) error {
177 calls += "group_a_3:"

Callers

nothing calls this directly

Calls 11

NewRouterFunction · 0.92
GETMethod · 0.80
GroupMethod · 0.80
BuildMuxMethod · 0.80
NextMethod · 0.65
CloseMethod · 0.65
ClientMethod · 0.65
DoMethod · 0.65
BindMethod · 0.45
UnbindMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…