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

Function TestEchoServeHTTPPathEncoding

echo_test.go:955–995  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

953}
954
955func TestEchoServeHTTPPathEncoding(t *testing.T) {
956 e := New()
957 e.GET("/with/slash", func(c *Context) error {
958 return c.String(http.StatusOK, "/with/slash")
959 })
960 e.GET("/:id", func(c *Context) error {
961 return c.String(http.StatusOK, c.Param("id"))
962 })
963
964 var testCases = []struct {
965 name string
966 whenURL string
967 expectURL string
968 expectStatus int
969 }{
970 {
971 name: "url with encoding is not decoded for routing",
972 whenURL: "/with%2Fslash",
973 expectURL: "with%2Fslash", // `%2F` is not decoded to `/` for routing
974 expectStatus: http.StatusOK,
975 },
976 {
977 name: "url without encoding is used as is",
978 whenURL: "/with/slash",
979 expectURL: "/with/slash",
980 expectStatus: http.StatusOK,
981 },
982 }
983
984 for _, tc := range testCases {
985 t.Run(tc.name, func(t *testing.T) {
986 req := httptest.NewRequest(http.MethodGet, tc.whenURL, nil)
987 rec := httptest.NewRecorder()
988
989 e.ServeHTTP(rec, req)
990
991 assert.Equal(t, tc.expectStatus, rec.Code)
992 assert.Equal(t, tc.expectURL, rec.Body.String())
993 })
994 }
995}
996
997func TestEchoGroup(t *testing.T) {
998 e := New()

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
ParamMethod · 0.80
ServeHTTPMethod · 0.80
GETMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…