-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patheventtype-formatdescription_test.go
100 lines (79 loc) · 2.36 KB
/
eventtype-formatdescription_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package binlog
import (
"testing"
"github.com/stretchr/testify/assert"
)
var (
formatEventHeader = []byte{
// Seconds since UNIX epoch
0x52, 0x52, 0xe9, 0x53,
// MySQL-defined binlog event type
0xf,
// ID of the originating MySQL server; used to filter out events in circular replication
0x88, 0xf3, 0x0, 0x0,
// Event size, including header, post-header, and body
0x67, 0x0, 0x0, 0x0,
// Position of the next event
0x0, 0x0, 0x0, 0x0,
// MySQL-defined binlog event flag
0x0, 0x0,
}
formatDescriptionEvent = []byte{
// Binlog version
4, 0,
// Server version
53, 46, 53, 46, 51, 52, 45, 51, 50, 46,
48, 45, 108, 111, 103, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// Created timestamp
0, 0, 0, 0,
// Total header size
19,
// Fixed length data size per event type
56, 13, 0, 8, 0, 18, 0, 4, 4, 4, 4, 18, 0, 0, 84, 0, 4,
26, 8, 0, 0, 0, 8, 8, 8, 2, 0,
}
)
func TestEventHeaderTypeIsFormatDescription(t *testing.T) {
input := formatEventHeader
want := FORMAT_DESCRIPTION_EVENT
h, err := NewEventHeader(input)
if assert.NoError(t, err) {
assert.Equal(t, h.EventType, want)
}
}
func TestEventCanBeParsedAsFormatDescriptionEvent(t *testing.T) {
input := formatDescriptionEvent
_, err := NewFormatDescriptionEvent(input)
assert.NoError(t, err)
}
func TestEventCanBeCastAsFormatDescriptionEvent(t *testing.T) {
input := formatDescriptionEvent
ev, _ := NewFormatDescriptionEvent(input)
_, ok := ev.(*FormatDescriptionEvent)
assert.True(t, ok)
}
func TestParsesFormatDescriptionEventBinlogVersionCorrectly(t *testing.T) {
input := formatDescriptionEvent
want := uint16(4)
ev, _ := NewFormatDescriptionEvent(input)
fd, _ := ev.(*FormatDescriptionEvent)
assert.EqualValues(t, fd.BinlogVersion, want)
}
func TestParsesFormatDescriptionEventServerVersionCorrectly(t *testing.T) {
input := formatDescriptionEvent
want := make([]byte, 50)
copy(want, "5.5.34-32.0-log")
ev, _ := NewFormatDescriptionEvent(input)
fd, _ := ev.(*FormatDescriptionEvent)
assert.EqualValues(t, fd.ServerVersion, want)
}
func TestParsesFormatDescriptionEventCreationTimestampCorrectly(t *testing.T) {
input := formatDescriptionEvent
want := uint32(0)
ev, _ := NewFormatDescriptionEvent(input)
fd, _ := ev.(*FormatDescriptionEvent)
assert.EqualValues(t, fd.CreationTimestamp, want)
}