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

Function TestBodyLimitReader

middleware/body_limit_test.go:96–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

94}
95
96func TestBodyLimitReader(t *testing.T) {
97 hw := []byte("Hello, World!")
98
99 config := BodyLimitConfig{
100 Skipper: DefaultSkipper,
101 LimitBytes: 2,
102 }
103 reader := &limitedReader{
104 BodyLimitConfig: config,
105 reader: io.NopCloser(bytes.NewReader(hw)),
106 }
107
108 // read all should return ErrStatusRequestEntityTooLarge
109 _, err := io.ReadAll(reader)
110 he := err.(echo.HTTPStatusCoder)
111 assert.Equal(t, http.StatusRequestEntityTooLarge, he.StatusCode())
112
113 // reset reader and read two bytes must succeed
114 bt := make([]byte, 2)
115 reader.Reset(io.NopCloser(bytes.NewReader(hw)))
116 n, err := reader.Read(bt)
117 assert.Equal(t, 2, n)
118 assert.Equal(t, nil, err)
119}
120
121func TestBodyLimit_skipper(t *testing.T) {
122 e := echo.New()

Callers

nothing calls this directly

Calls 3

ResetMethod · 0.95
ReadMethod · 0.95
StatusCodeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…