MCPcopy
hub / github.com/grpc/grpc-go / mustCompress

Function mustCompress

rpc_util_test.go:424–436  ·  view source on GitHub ↗

mustCompress gzip-compresses input and returns it as a BufferSlice, failing the test if compression fails.

(t *testing.T, input []byte)

Source from the content-addressed store, hash-verified

422// mustCompress gzip-compresses input and returns it as a BufferSlice,
423// failing the test if compression fails.
424func 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.

Callers 2

TestDecompressMethod · 0.85

Calls 5

NewBufferFunction · 0.92
WriteMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
BytesMethod · 0.65

Tested by

no test coverage detected