MCPcopy
hub / github.com/pocketbase/pocketbase / TestRouterGroupHasRoute

Function TestRouterGroupHasRoute

tools/router/group_test.go:317–430  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

315}
316
317func TestRouterGroupHasRoute(t *testing.T) {
318 t.Parallel()
319
320 group := RouterGroup[*Event]{}
321
322 group.Any("/any", nil)
323
324 group.GET("/base", nil)
325 group.DELETE("/base", nil)
326
327 sub := group.Group("/sub1")
328 sub.GET("/a", nil)
329 sub.POST("/a", nil)
330
331 sub2 := sub.Group("/sub2")
332 sub2.GET("/b", nil)
333 sub2.GET("/b/{test}", nil)
334
335 // special cases to test the normalizations
336 group.GET("/c/", nil) // the same as /c/{test...}
337 group.GET("/d/{test...}", nil) // the same as /d/
338
339 scenarios := []struct {
340 method string
341 path string
342 expected bool
343 }{
344 {
345 http.MethodGet,
346 "",
347 false,
348 },
349 {
350 "",
351 "/any",
352 true,
353 },
354 {
355 http.MethodPost,
356 "/base",
357 false,
358 },
359 {
360 http.MethodGet,
361 "/base",
362 true,
363 },
364 {
365 http.MethodDelete,
366 "/base",
367 true,
368 },
369 {
370 http.MethodGet,
371 "/sub1",
372 false,
373 },
374 {

Callers

nothing calls this directly

Calls 7

AnyMethod · 0.80
GETMethod · 0.80
DELETEMethod · 0.80
GroupMethod · 0.80
POSTMethod · 0.80
HasRouteMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…