@@ -11,6 +11,7 @@ import (
11
11
12
12
. "github.com/pingcap/check"
13
13
"github.com/siddontang/go-mysql/client"
14
+ "github.com/siddontang/go-mysql/mysql"
14
15
)
15
16
16
17
// use docker mysql for test
@@ -113,16 +114,88 @@ func (s *schemaTestSuite) TestDump(c *C) {
113
114
}
114
115
115
116
type testParseHandler struct {
117
+ gset mysql.GTIDSet
116
118
}
117
119
118
120
func (h * testParseHandler ) BinLog (name string , pos uint64 ) error {
119
121
return nil
120
122
}
121
123
124
+ func (h * testParseHandler ) GtidSet (gtidsets string ) (err error ) {
125
+ if h .gset != nil {
126
+ err = h .gset .Update (gtidsets )
127
+ } else {
128
+ h .gset , err = mysql .ParseGTIDSet ("mysql" , gtidsets )
129
+ }
130
+ return err
131
+ }
132
+
122
133
func (h * testParseHandler ) Data (schema string , table string , values []string ) error {
123
134
return nil
124
135
}
125
136
137
+ type GtidParseTest struct {
138
+ gset mysql.GTIDSet
139
+ }
140
+
141
+ func (h * GtidParseTest ) UpdateGtidSet (gtidStr string ) (err error ) {
142
+ if h .gset != nil {
143
+ err = h .gset .Update (gtidStr )
144
+ } else {
145
+ h .gset , err = mysql .ParseGTIDSet ("mysql" , gtidStr )
146
+ }
147
+ return err
148
+ }
149
+
150
+ func (s * parserTestSuite ) TestParseGtidExp (c * C ) {
151
+ // binlogExp := regexp.MustCompile("^CHANGE MASTER TO MASTER_LOG_FILE='(.+)', MASTER_LOG_POS=(\\d+);")
152
+ // gtidExp := regexp.MustCompile("(\\w{8}(-\\w{4}){3}-\\w{12}:\\d+-\\d+)")
153
+ tbls := []struct {
154
+ input string
155
+ expected string
156
+ }{
157
+ {`SET @@GLOBAL.GTID_PURGED='071a84e8-b253-11e8-8472-005056a27e86:1-76,
158
+ 2337be48-0456-11e9-bd1c-00505690543b:1-7,
159
+ 41d816cd-0455-11e9-be42-005056901a22:1-2,
160
+ 5f1eea9e-b1e5-11e8-bc77-005056a221ed:1-144609156,
161
+ 75848cdb-8131-11e7-b6fc-1c1b0de85e7b:1-151378598,
162
+ 780ad602-0456-11e9-8bcd-005056901a22:1-516653148,
163
+ 92809ddd-1e3c-11e9-9d04-00505690f6ab:1-11858565,
164
+ c59598c7-0467-11e9-bbbe-005056901a22:1-226464969,
165
+ cbd7809d-0433-11e9-b1cf-00505690543b:1-18233950,
166
+ cca778e9-8cdf-11e8-94d0-005056a247b1:1-303899574,
167
+ cf80679b-7695-11e8-8873-1c1b0d9a4ab9:1-12836047,
168
+ d0951f24-1e21-11e9-bb2e-00505690b730:1-4758092,
169
+ e7574090-b123-11e8-8bb4-005056a29643:1-12'
170
+ ` , "071a84e8-b253-11e8-8472-005056a27e86:1-76,2337be48-0456-11e9-bd1c-00505690543b:1-7,41d816cd-0455-11e9-be42-005056901a22:1-2,5f1eea9e-b1e5-11e8-bc77-005056a221ed:1-144609156,75848cdb-8131-11e7-b6fc-1c1b0de85e7b:1-151378598,780ad602-0456-11e9-8bcd-005056901a22:1-516653148,92809ddd-1e3c-11e9-9d04-00505690f6ab:1-11858565,c59598c7-0467-11e9-bbbe-005056901a22:1-226464969,cbd7809d-0433-11e9-b1cf-00505690543b:1-18233950,cca778e9-8cdf-11e8-94d0-005056a247b1:1-303899574,cf80679b-7695-11e8-8873-1c1b0d9a4ab9:1-12836047,d0951f24-1e21-11e9-bb2e-00505690b730:1-4758092,e7574090-b123-11e8-8bb4-005056a29643:1-12" },
171
+ {`SET @@GLOBAL.GTID_PURGED='071a84e8-b253-11e8-8472-005056a27e86:1-76,
172
+ 2337be48-0456-11e9-bd1c-00505690543b:1-7';
173
+ ` , "071a84e8-b253-11e8-8472-005056a27e86:1-76,2337be48-0456-11e9-bd1c-00505690543b:1-7" },
174
+ {`SET @@GLOBAL.GTID_PURGED='c0977f88-3104-11e9-81e1-00505690245b:1-274559';
175
+ ` , "c0977f88-3104-11e9-81e1-00505690245b:1-274559" },
176
+ {`CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.008995', MASTER_LOG_POS=102052485;` , "" },
177
+ }
178
+
179
+ for _ , tt := range tbls {
180
+ reader := strings .NewReader (tt .input )
181
+ var handler = new (testParseHandler )
182
+
183
+ Parse (reader , handler , true )
184
+
185
+ if tt .expected == "" {
186
+ if handler .gset != nil {
187
+ c .Assert (handler .gset , IsNil )
188
+ } else {
189
+ continue
190
+ }
191
+ }
192
+ expectedGtidset , err := mysql .ParseGTIDSet ("mysql" , tt .expected )
193
+ c .Assert (err , IsNil )
194
+ c .Assert (expectedGtidset .Equal (handler .gset ), IsTrue )
195
+ }
196
+
197
+ }
198
+
126
199
func (s * parserTestSuite ) TestParseFindTable (c * C ) {
127
200
tbl := []struct {
128
201
sql string
0 commit comments