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

Function TestDecompress

middleware/decompress_test.go:21–44  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestDecompress(t *testing.T) {
22 e := echo.New()
23
24 h := Decompress()(func(c *echo.Context) error {
25 c.Response().Write([]byte("test")) // For Content-Type sniffing
26 return nil
27 })
28
29 // Decompress request body
30 body := `{"name": "echo"}`
31 gz, _ := gzipString(body)
32 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(string(gz)))
33 req.Header.Set(echo.HeaderContentEncoding, GZIPEncoding)
34 rec := httptest.NewRecorder()
35 c := e.NewContext(req, rec)
36
37 err := h(c)
38 assert.NoError(t, err)
39
40 assert.Equal(t, GZIPEncoding, req.Header.Get(echo.HeaderContentEncoding))
41 b, err := io.ReadAll(req.Body)
42 assert.NoError(t, err)
43 assert.Equal(t, body, string(b))
44}
45
46func TestDecompress_skippedIfNoHeader(t *testing.T) {
47 e := echo.New()

Callers

nothing calls this directly

Calls 7

ResponseMethod · 0.95
DecompressFunction · 0.85
gzipStringFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
WriteMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…