MCPcopy Index your code
hub / github.com/labstack/echo / TestRouterOptionsMethodHandler

Function TestRouterOptionsMethodHandler

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

Source from the content-addressed store, hash-verified

899}
900
901func TestRouterOptionsMethodHandler(t *testing.T) {
902 e := New()
903
904 var keyInContext any
905 e.Use(func(next HandlerFunc) HandlerFunc {
906 return func(c *Context) error {
907 err := next(c)
908 keyInContext = c.Get(ContextKeyHeaderAllow)
909 return err
910 }
911 })
912 e.GET("/test", func(c *Context) error {
913 return c.String(http.StatusOK, "Echo!")
914 })
915
916 req := httptest.NewRequest(http.MethodOptions, "/test", nil)
917 rec := httptest.NewRecorder()
918 e.ServeHTTP(rec, req)
919
920 assert.Equal(t, http.StatusNoContent, rec.Code)
921 assert.Equal(t, "OPTIONS, GET", rec.Header().Get(HeaderAllow))
922 assert.Equal(t, "OPTIONS, GET", keyInContext)
923}
924
925func TestRouterHandleMethodOptions(t *testing.T) {
926 e := New()

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
ServeHTTPMethod · 0.80
UseMethod · 0.45
GetMethod · 0.45
GETMethod · 0.45
StringMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…