MCPcopy
hub / github.com/labstack/echo / TestRouter_addAndMatchAllSupportedMethods

Function TestRouter_addAndMatchAllSupportedMethods

router_test.go:745–803  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

743}
744
745func TestRouter_addAndMatchAllSupportedMethods(t *testing.T) {
746 var testCases = []struct {
747 name string
748 whenMethod string
749 expectPath string
750 expectError string
751 givenNoAddRoute bool
752 }{
753 {name: "ok, CONNECT", whenMethod: http.MethodConnect},
754 {name: "ok, DELETE", whenMethod: http.MethodDelete},
755 {name: "ok, GET", whenMethod: http.MethodGet},
756 {name: "ok, HEAD", whenMethod: http.MethodHead},
757 {name: "ok, OPTIONS", whenMethod: http.MethodOptions},
758 {name: "ok, PATCH", whenMethod: http.MethodPatch},
759 {name: "ok, POST", whenMethod: http.MethodPost},
760 {name: "ok, PROPFIND", whenMethod: PROPFIND},
761 {name: "ok, PUT", whenMethod: http.MethodPut},
762 {name: "ok, TRACE", whenMethod: http.MethodTrace},
763 {name: "ok, REPORT", whenMethod: REPORT},
764 {name: "ok, NON_TRADITIONAL_METHOD", whenMethod: "NON_TRADITIONAL_METHOD"},
765 {
766 name: "ok, NOT_EXISTING_METHOD",
767 whenMethod: "NOT_EXISTING_METHOD",
768 givenNoAddRoute: true,
769 expectPath: "/*",
770 expectError: "Method Not Allowed",
771 },
772 }
773
774 for _, tc := range testCases {
775 t.Run(tc.name, func(t *testing.T) {
776 e := New()
777
778 e.GET("/*", handlerFunc)
779 if !tc.givenNoAddRoute {
780 e.Add(tc.whenMethod, "/my/*", handlerFunc)
781 }
782
783 req := httptest.NewRequest(tc.whenMethod, "/my/some-url", nil)
784 rec := httptest.NewRecorder()
785 c := e.NewContext(req, rec)
786
787 handler := e.router.Route(c)
788 err := handler(c)
789
790 if tc.expectError != "" {
791 assert.EqualError(t, err, tc.expectError)
792 } else {
793 assert.NoError(t, err)
794 }
795
796 expectPath := "/my/*"
797 if tc.expectPath != "" {
798 expectPath = tc.expectPath
799 }
800 assert.Equal(t, expectPath, c.Path())
801 })
802 }

Callers

nothing calls this directly

Calls 6

PathMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80
AddMethod · 0.65
RouteMethod · 0.65
GETMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…