(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func 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 | |
| 46 | func TestDecompress_skippedIfNoHeader(t *testing.T) { |
| 47 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…