MCPcopy
hub / github.com/IBM/sarama / TestDefaultRecords

Function TestDefaultRecords

records_test.go:86–161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestDefaultRecords(t *testing.T) {
87 batch := &RecordBatch{
88 IsTransactional: true,
89 Version: 2,
90 FirstOffset: 1,
91 Records: []*Record{
92 {
93 Value: []byte{1},
94 },
95 },
96 }
97
98 r := newDefaultRecords(batch)
99
100 exp, err := encode(batch, nil)
101 if err != nil {
102 t.Fatal(err)
103 }
104 buf, err := encode(&r, nil)
105 if err != nil {
106 t.Fatal(err)
107 }
108 if !bytes.Equal(buf, exp) {
109 t.Errorf("Wrong encoding for default records, wanted %v, got %v", exp, buf)
110 }
111
112 batch = &RecordBatch{}
113 r = Records{}
114
115 err = decode(exp, batch, nil)
116 if err != nil {
117 t.Fatal(err)
118 }
119 err = decode(buf, &r, nil)
120 if err != nil {
121 t.Fatal(err)
122 }
123
124 if r.recordsType != defaultRecords {
125 t.Fatalf("Wrong records type %v, expected %v", r.recordsType, defaultRecords)
126 }
127 if !reflect.DeepEqual(batch, r.RecordBatch) {
128 t.Errorf("Wrong decoding for default records, wanted %#+v, got %#+v", batch, r.RecordBatch)
129 }
130
131 n, err := r.numRecords()
132 if err != nil {
133 t.Fatal(err)
134 }
135 if n != 1 {
136 t.Errorf("Wrong number of records, wanted 1, got %d", n)
137 }
138
139 p, err := r.isPartial()
140 if err != nil {
141 t.Fatal(err)
142 }
143 if p {

Callers

nothing calls this directly

Calls 10

newDefaultRecordsFunction · 0.85
encodeFunction · 0.85
decodeFunction · 0.85
FatalMethod · 0.80
FatalfMethod · 0.80
isControlMethod · 0.80
nextOffsetMethod · 0.80
ErrorfMethod · 0.65
numRecordsMethod · 0.45
isPartialMethod · 0.45

Tested by

no test coverage detected