mysqlbinlog/get_gtid_of_binlog_test.go

31 lines
725 B
Go
Raw Normal View History

2023-04-25 18:41:34 +08:00
package binlog
import (
"strings"
2023-04-25 18:41:34 +08:00
"testing"
)
func TestGetGtidOfBinlog(t *testing.T) {
desc, err := GetGtidOfBinlog("./test/mysql-bin56.000003")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if "F60AB33CC60411E38E1CE66CCF50DB66:1-136" != normalizeGtidForTest(desc) {
2023-04-25 18:41:34 +08:00
t.Fatalf("wrong gtid %v", desc)
}
}
func normalizeGtidForTest(desc string) string {
parts := strings.Split(desc, ",")
for i, part := range parts {
gtidParts := strings.SplitN(part, ":", 2)
if len(gtidParts) != 2 {
parts[i] = strings.ToUpper(part)
continue
}
uuid := strings.ReplaceAll(strings.ToUpper(gtidParts[0]), "-", "")
parts[i] = uuid + ":" + strings.ToUpper(gtidParts[1])
}
return strings.Join(parts, ",")
}