mustCompress gzip-compresses input and returns it as a BufferSlice, failing the test if compression fails.
(t *testing.T, input []byte)
| 422 | // mustCompress gzip-compresses input and returns it as a BufferSlice, |
| 423 | // failing the test if compression fails. |
| 424 | func mustCompress(t *testing.T, input []byte) mem.BufferSlice { |
| 425 | t.Helper() |
| 426 | var buf bytes.Buffer |
| 427 | gz := gzip.NewWriter(&buf) |
| 428 | if _, err := gz.Write(input); err != nil { |
| 429 | t.Fatalf("mustCompress() failed to write data: %v", err) |
| 430 | } |
| 431 | if err := gz.Close(); err != nil { |
| 432 | t.Fatalf("mustCompress() failed to close gzip writer: %v", err) |
| 433 | } |
| 434 | compressedData := buf.Bytes() |
| 435 | return mem.BufferSlice{mem.NewBuffer(&compressedData, nil)} |
| 436 | } |
| 437 | |
| 438 | // MockDecompressor is a mock implementation of a decompressor used for testing purposes. |
| 439 | // It simulates decompression behavior, returning either decompressed data or an error based on the ShouldError flag. |