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

Function TestLegacyRecords

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

Source from the content-addressed store, hash-verified

9)
10
11func TestLegacyRecords(t *testing.T) {
12 set := &MessageSet{
13 Messages: []*MessageBlock{
14 {
15 Msg: &Message{
16 Version: 1,
17 },
18 },
19 },
20 }
21 r := newLegacyRecords(set)
22
23 exp, err := encode(set, nil)
24 if err != nil {
25 t.Fatal(err)
26 }
27 buf, err := encode(&r, nil)
28 if err != nil {
29 t.Fatal(err)
30 }
31 if !bytes.Equal(buf, exp) {
32 t.Errorf("Wrong encoding for legacy records, wanted %v, got %v", exp, buf)
33 }
34
35 set = &MessageSet{}
36 r = Records{}
37
38 err = decode(exp, set, nil)
39 if err != nil {
40 t.Fatal(err)
41 }
42 err = decode(buf, &r, nil)
43 if err != nil {
44 t.Fatal(err)
45 }
46
47 if r.recordsType != legacyRecords {
48 t.Fatalf("Wrong records type %v, expected %v", r.recordsType, legacyRecords)
49 }
50 if !reflect.DeepEqual(set, r.MsgSet) {
51 t.Errorf("Wrong decoding for legacy records, wanted %#+v, got %#+v", set, r.MsgSet)
52 }
53
54 n, err := r.numRecords()
55 if err != nil {
56 t.Fatal(err)
57 }
58 if n != 1 {
59 t.Errorf("Wrong number of records, wanted 1, got %d", n)
60 }
61
62 p, err := r.isPartial()
63 if err != nil {
64 t.Fatal(err)
65 }
66 if p {
67 t.Errorf("MessageSet shouldn't have a partial trailing message")
68 }

Callers

nothing calls this directly

Calls 10

newLegacyRecordsFunction · 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