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

Function TestWriteVarInt

write_test.go:26–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func TestWriteVarInt(t *testing.T) {
27 testCases := []*WriteVarIntTestCase{
28 {v: []byte{0}, tc: 0},
29 {v: []byte{2}, tc: 1},
30 {v: []byte{1}, tc: -1},
31 {v: []byte{3}, tc: -2},
32 {v: []byte{128, 2}, tc: 128},
33 {v: []byte{254, 1}, tc: 127},
34 {v: []byte{142, 6}, tc: 391},
35 {v: []byte{142, 134, 6}, tc: 49543},
36 }
37
38 for _, tc := range testCases {
39 b := &bytes.Buffer{}
40 w := &writeBuffer{w: b}
41 w.writeVarInt(tc.tc)
42
43 if !bytes.Equal(b.Bytes(), tc.v) {
44 t.Errorf("Expected %v; got %v", tc.v, b.Bytes())
45 }
46 }
47}
48
49func TestWriteOptimizations(t *testing.T) {
50 t.Run("writeFetchRequestV2", testWriteFetchRequestV2)

Callers

nothing calls this directly

Calls 2

writeVarIntMethod · 0.95
BytesMethod · 0.65

Tested by

no test coverage detected