Skip to content

Commit 4a8e497

Browse files
committed
More testing
1 parent 28d3be8 commit 4a8e497

File tree

1 file changed

+176
-4
lines changed

1 file changed

+176
-4
lines changed

serialization/serialization_test.go

Lines changed: 176 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestDecodeVar(t *testing.T) {
154154
"",
155155
},
156156
{
157-
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
157+
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlhtml
158158
// But converted to LE
159159
// unsigned integer, 65535
160160
[]byte{0b11111011, 0b11111111, 0b00000111},
@@ -163,7 +163,7 @@ func TestDecodeVar(t *testing.T) {
163163
"",
164164
},
165165
{
166-
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
166+
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlhtml
167167
// But converted to LE
168168
// signed integer, 65535
169169
[]byte{0b11110011, 0b11111111, 0b00001111},
@@ -172,7 +172,7 @@ func TestDecodeVar(t *testing.T) {
172172
"",
173173
},
174174
{
175-
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
175+
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlhtml
176176
// But converted to LE
177177
// signed integer, -65535
178178
[]byte{0b11101011, 0b11111111, 0b00001111},
@@ -181,7 +181,7 @@ func TestDecodeVar(t *testing.T) {
181181
"",
182182
},
183183
{
184-
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
184+
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlhtml
185185
// But converted to LE
186186
// signed integer, 65536
187187
[]byte{0b11111011, 0b11111111, 0b00001111},
@@ -213,3 +213,175 @@ func TestDecodeVar(t *testing.T) {
213213
}
214214
}
215215
}
216+
217+
func TestUmarshal_event1(t *testing.T) {
218+
data := []byte{0x2, 0x76, 0x0, 0x0, 0x2, 0x2, 0x25, 0x2, 0xdc, 0xf0, 0x9, 0x2, 0x30, 0xf9, 0x3, 0x22, 0xbd, 0x3,
219+
0xad, 0x2, 0x21, 0x2, 0x44, 0x44, 0x5a, 0x68, 0x51, 0x3, 0x22, 0x4, 0x4, 0x6, 0xc, 0x66, 0x6f, 0x6f, 0x62,
220+
0x61, 0x7a, 0x8, 0x0, 0xa, 0x4, 0xc, 0x7f, 0x15, 0x83, 0x22, 0x2d, 0x5c, 0x2e, 0x6, 0x10, 0x49, 0x3, 0x12,
221+
0xc3, 0x2, 0xb}
222+
223+
msg := Message{
224+
Format: Format{
225+
Fields: []Field{
226+
{
227+
Name: "gtid_flags",
228+
Type: FieldIntFixed{
229+
Length: 1,
230+
},
231+
},
232+
{
233+
Name: "uuid",
234+
Type: FieldIntFixed{
235+
Length: 16,
236+
},
237+
},
238+
{
239+
Name: "gno",
240+
Type: FieldIntVar{},
241+
},
242+
{
243+
Name: "tag",
244+
Type: FieldString{},
245+
},
246+
{
247+
Name: "last_committed",
248+
Type: FieldIntVar{},
249+
},
250+
{
251+
Name: "sequence_number",
252+
Type: FieldIntVar{},
253+
},
254+
{
255+
Name: "immediate_commit_timestamp",
256+
Type: FieldUintVar{},
257+
},
258+
{
259+
Name: "original_commit_timestamp",
260+
Type: FieldUintVar{},
261+
Optional: true,
262+
},
263+
{
264+
Name: "transaction_length",
265+
Type: FieldUintVar{},
266+
},
267+
{
268+
Name: "immediate_server_version",
269+
Type: FieldUintVar{},
270+
},
271+
{
272+
Name: "original_server_version",
273+
Type: FieldUintVar{},
274+
Optional: true,
275+
},
276+
{
277+
Name: "commit_group_ticket",
278+
Optional: true,
279+
},
280+
},
281+
},
282+
}
283+
284+
expected := Message{
285+
Version: 1,
286+
Format: Format{
287+
Size: 59,
288+
Fields: []Field{
289+
{
290+
Name: "gtid_flags",
291+
ID: 0,
292+
Type: FieldIntFixed{
293+
Length: 1,
294+
Value: []uint8{01},
295+
},
296+
},
297+
{
298+
Name: "uuid",
299+
ID: 1,
300+
Type: FieldIntFixed{
301+
Length: 16,
302+
Value: []uint8{0x89, 0x6e, 0x78, 0x82, 0x18, 0xfe, 0x11, 0xef, 0xab,
303+
0x88, 0x22, 0x22, 0x2d, 0x34, 0xd4, 0x11},
304+
},
305+
},
306+
{
307+
Name: "gno",
308+
ID: 2,
309+
Type: FieldIntVar{
310+
Value: 1,
311+
},
312+
},
313+
{
314+
Name: "tag",
315+
ID: 3,
316+
Type: FieldString{
317+
Value: "foobaz",
318+
},
319+
},
320+
{
321+
Name: "last_committed",
322+
ID: 4,
323+
Type: FieldIntVar{
324+
Value: 0,
325+
},
326+
},
327+
{
328+
Name: "sequence_number",
329+
ID: 5,
330+
Type: FieldIntVar{
331+
Value: 1,
332+
},
333+
},
334+
{
335+
Name: "immediate_commit_timestamp",
336+
ID: 6,
337+
Type: FieldUintVar{
338+
Value: 1739823289369365,
339+
},
340+
},
341+
{
342+
Name: "original_commit_timestamp",
343+
ID: 7,
344+
Type: FieldUintVar{},
345+
Optional: true,
346+
Skipped: true,
347+
},
348+
{
349+
Name: "transaction_length",
350+
ID: 8,
351+
Type: FieldUintVar{
352+
Value: 210,
353+
},
354+
},
355+
{
356+
Name: "immediate_server_version",
357+
ID: 9,
358+
Type: FieldUintVar{
359+
Value: 90200,
360+
},
361+
},
362+
{
363+
Name: "original_server_version",
364+
ID: 10,
365+
Type: FieldUintVar{},
366+
Optional: true,
367+
Skipped: true,
368+
},
369+
{
370+
Name: "commit_group_ticket",
371+
ID: 11,
372+
Optional: true,
373+
Skipped: true,
374+
},
375+
},
376+
},
377+
}
378+
379+
err := Unmarshal(data, &msg)
380+
require.NoError(t, err)
381+
382+
for i, f := range msg.Format.Fields {
383+
require.Equal(t, expected.Format.Fields[i], f)
384+
}
385+
386+
require.Equal(t, expected, msg)
387+
}

0 commit comments

Comments
 (0)