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

Function TestControlRecord

protocol/record_batch_test.go:100–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

98}
99
100func TestControlRecord(t *testing.T) {
101 now := time.Now()
102
103 records := []ControlRecord{
104 {
105 Offset: 1,
106 Time: now,
107 Version: 2,
108 Type: 3,
109 },
110 {
111 Offset: 2,
112 Time: now.Add(time.Second),
113 Version: 4,
114 Type: 5,
115 Data: []byte("Hello World!"),
116 Headers: []Header{
117 {Key: "answer", Value: []byte("42")},
118 },
119 },
120 }
121
122 batch := NewControlBatch(records...)
123 found := make([]ControlRecord, 0, len(records))
124
125 for {
126 r, err := batch.ReadControlRecord()
127 if err != nil {
128 if !errors.Is(err, io.EOF) {
129 t.Fatal(err)
130 }
131 break
132 }
133 found = append(found, *r)
134 }
135
136 if !reflect.DeepEqual(records, found) {
137 t.Error("control records mismatch")
138 }
139}
140
141func assertRecords(t *testing.T, r1, r2 RecordReader) {
142 t.Helper()

Callers

nothing calls this directly

Calls 3

ReadControlRecordMethod · 0.95
NewControlBatchFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected