MCPcopy
hub / github.com/gin-gonic/gin / TestRouteContextHoldsFullPath

Function TestRouteContextHoldsFullPath

routes_test.go:731–772  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

729}
730
731func TestRouteContextHoldsFullPath(t *testing.T) {
732 router := New()
733
734 // Test routes
735 routes := []string{
736 "/simple",
737 "/project/:name",
738 "/",
739 "/news/home",
740 "/news",
741 "/simple-two/one",
742 "/simple-two/one-two",
743 "/project/:name/build/*params",
744 "/project/:name/bui",
745 "/user/:id/status",
746 "/user/:id",
747 "/user/:id/profile",
748 }
749
750 for _, route := range routes {
751 actualRoute := route
752 router.GET(route, func(c *Context) {
753 // For each defined route context should contain its full path
754 assert.Equal(t, actualRoute, c.FullPath())
755 c.AbortWithStatus(http.StatusOK)
756 })
757 }
758
759 for _, route := range routes {
760 w := PerformRequest(router, http.MethodGet, route)
761 assert.Equal(t, http.StatusOK, w.Code)
762 }
763
764 // Test not found
765 router.Use(func(c *Context) {
766 // For not found routes full path is empty
767 assert.Empty(t, c.FullPath())
768 })
769
770 w := PerformRequest(router, http.MethodGet, "/not-found")
771 assert.Equal(t, http.StatusNotFound, w.Code)
772}
773
774func TestEngineHandleMethodNotAllowedCornerCase(t *testing.T) {
775 r := New()

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
PerformRequestFunction · 0.85
FullPathMethod · 0.80
AbortWithStatusMethod · 0.80
GETMethod · 0.65
UseMethod · 0.65

Tested by

no test coverage detected