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

Function TestContextTimeoutTestRequestClone

middleware/context_timeout_test.go:103–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

101}
102
103func TestContextTimeoutTestRequestClone(t *testing.T) {
104 t.Parallel()
105 req := httptest.NewRequest(http.MethodPost, "/uri?query=value", strings.NewReader(url.Values{"form": {"value"}}.Encode()))
106 req.AddCookie(&http.Cookie{Name: "cookie", Value: "value"})
107 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
108 rec := httptest.NewRecorder()
109
110 m := ContextTimeoutWithConfig(ContextTimeoutConfig{
111 // Timeout has to be defined or the whole flow for timeout middleware will be skipped
112 Timeout: 1 * time.Second,
113 })
114
115 e := echo.New()
116 c := e.NewContext(req, rec)
117
118 err := m(func(c *echo.Context) error {
119 // Cookie test
120 cookie, err := c.Request().Cookie("cookie")
121 if assert.NoError(t, err) {
122 assert.EqualValues(t, "cookie", cookie.Name)
123 assert.EqualValues(t, "value", cookie.Value)
124 }
125
126 // Form values
127 if assert.NoError(t, c.Request().ParseForm()) {
128 assert.EqualValues(t, "value", c.Request().FormValue("form"))
129 }
130
131 // Query string
132 assert.EqualValues(t, "value", c.Request().URL.Query()["query"][0])
133 return nil
134 })(c)
135
136 assert.NoError(t, err)
137}
138
139func TestContextTimeoutWithDefaultErrorMessage(t *testing.T) {
140 t.Parallel()

Callers

nothing calls this directly

Calls 6

RequestMethod · 0.95
ContextTimeoutWithConfigFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
CookieMethod · 0.80
FormValueMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…