MCPcopy
hub / github.com/segmentio/kafka-go / TestXerialReaderWriter

Function TestXerialReaderWriter

compress/snappy/xerial_test.go:39–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37}
38
39func TestXerialReaderWriter(t *testing.T) {
40 rawData := new(bytes.Buffer)
41 rawData.Grow(1024 * 1024)
42 io.CopyN(rawData, rand.Reader, 1024*1024)
43
44 framedData := new(bytes.Buffer)
45 framedData.Grow(rawData.Len() + 1024)
46 w := simpleWriter{&xerialWriter{writer: framedData}}
47 r := simpleReader{bytes.NewReader(rawData.Bytes())}
48 io.Copy(w, r)
49 w.Writer.(*xerialWriter).Flush()
50
51 unframedData := new(bytes.Buffer)
52 unframedData.Grow(rawData.Len())
53 io.Copy(unframedData, &xerialReader{reader: framedData})
54
55 b0 := rawData.Bytes()
56 b1 := unframedData.Bytes()
57
58 if !bytes.Equal(b0, b1) {
59 t.Error("data mismatch")
60 }
61}
62
63func TestXerialFramedCompression(t *testing.T) {
64 rawData := new(bytes.Buffer)

Callers

nothing calls this directly

Calls 5

LenMethod · 0.65
NewReaderMethod · 0.65
BytesMethod · 0.65
FlushMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected