mysqlbinlog/dump_binlog_from_pos_test.go
starainrt 0c9d9c6eae
feat(binlog): 增加 logical clock 元数据解析与统计支撑
- 暴露事务级 last_committed、sequence_number、transaction_length 和 commit timestamp
- 在 GTID event 转换时透传 logical clock 元数据
- 新增 ParseOptions、ParseProgress,支持上下文取消和解析进度回调
- 保留 TransactionPayloadEvent 展开后的 tablemap 与压缩类型信息
- 增加 TransactionSummary 辅助结构,便于上层统计事务结果、耗时、表分布和逻辑时钟
- 清理测试对外部大 binlog 样本的依赖,保证独立库测试可运行
- 修正跨平台测试与 GTID 输出格式断言,提升发版稳定性
2026-05-10 14:02:53 +08:00

60 lines
2.3 KiB
Go

package binlog
import (
"os"
"os/exec"
"runtime"
"testing"
)
func requireBundledMysqlbinlog(t *testing.T) {
t.Helper()
if runtime.GOOS != "darwin" || runtime.GOARCH != "amd64" {
t.Skip("skips bundled mysqlbinlog validation: test/mysqlbinlog is a Darwin amd64 executable")
}
}
func TestDumpBinlogFromPos0(t *testing.T) {
requireBundledMysqlbinlog(t)
defer os.Remove("./test/test-mysql-bin-dump")
if err := DumpBinlogFromPos("./test/test-mysql-bin", 107, "./test/test-mysql-bin-dump"); nil != err {
t.Errorf("expect no err, but got %v", err)
}
if err := exec.Command("sh", "-c", "./test/mysqlbinlog ./test/test-mysql-bin-dump > /dev/null").Run(); nil != err {
t.Errorf("expect dump log could be parsed by mysqlbinlog, but failed with err=%v", err)
}
}
func TestDumpBinlogFromPos1(t *testing.T) {
requireBundledMysqlbinlog(t)
defer os.Remove("./test/test-mysql-bin-dump")
if err := DumpBinlogFromPos("./test/test-mysql-bin", 24959, "./test/test-mysql-bin-dump"); nil != err {
t.Errorf("expect no err, but got %v", err)
}
if err := exec.Command("sh", "-c", "./test/mysqlbinlog ./test/test-mysql-bin-dump > /dev/null").Run(); nil != err {
t.Errorf("expect dump log could be parsed by mysqlbinlog, but failed with err=%v", err)
}
}
func TestDumpUnexecutedBinlogByGtid(t *testing.T) {
requireBundledMysqlbinlog(t)
defer os.Remove("./test/test-mysql-bin-dump")
if err := DumpUnexecutedBinlogByGtid("./test/mysql-bin56.000003", "f60ab33c-c604-11e3-8e1c-e66ccf50db66:1-73", "./test/test-mysql-bin-dump", false); nil != err {
t.Errorf("expect no err, but got %v", err)
}
if err := exec.Command("sh", "-c", "./test/mysqlbinlog ./test/test-mysql-bin-dump > /dev/null").Run(); nil != err {
t.Errorf("expect dump log could be parsed by mysqlbinlog, but failed with err=%v", err)
}
}
func TestDumpBinlogWithOnlyHeader(t *testing.T) {
requireBundledMysqlbinlog(t)
defer os.Remove("./test/test-mysql-bin-dump")
if err := DumpBinlogFromPos("./test/only-header-mysql-bin", 231, "./test/test-mysql-bin-dump"); nil != err {
t.Errorf("expect no err, but got %v", err)
}
if err := exec.Command("sh", "-c", "./test/mysqlbinlog ./test/test-mysql-bin-dump > /dev/null").Run(); nil != err {
t.Errorf("expect dump log could be parsed by mysqlbinlog, but failed with err=%v", err)
}
}