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

Function TestGzipWithStatic

middleware/compress_test.go:189–217  ·  view source on GitHub ↗

Issue #806

(t *testing.T)

Source from the content-addressed store, hash-verified

187
188// Issue #806
189func TestGzipWithStatic(t *testing.T) {
190 e := echo.New()
191 e.Filesystem = os.DirFS("../")
192
193 e.Use(Gzip())
194 e.Static("/test", "_fixture/images")
195 req := httptest.NewRequest(http.MethodGet, "/test/walle.png", nil)
196 req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
197 rec := httptest.NewRecorder()
198
199 e.ServeHTTP(rec, req)
200
201 assert.Equal(t, http.StatusOK, rec.Code)
202 // Data is written out in chunks when Content-Length == "", so only
203 // validate the content length if it's not set.
204 if cl := rec.Header().Get("Content-Length"); cl != "" {
205 assert.Equal(t, cl, rec.Body.Len())
206 }
207 r, err := gzip.NewReader(rec.Body)
208 if assert.NoError(t, err) {
209 defer r.Close()
210 want, err := os.ReadFile("../_fixture/images/walle.png")
211 if assert.NoError(t, err) {
212 buf := new(bytes.Buffer)
213 buf.ReadFrom(r)
214 assert.Equal(t, want, buf.Bytes())
215 }
216 }
217}
218
219func TestGzipWithMinLength(t *testing.T) {
220 e := echo.New()

Callers

nothing calls this directly

Calls 8

GzipFunction · 0.85
SetMethod · 0.80
ServeHTTPMethod · 0.80
UseMethod · 0.45
StaticMethod · 0.45
GetMethod · 0.45
HeaderMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…