mysqlbinlog/parse_test.go

50 lines
909 B
Go
Raw Normal View History

2023-04-25 18:41:34 +08:00
package binlog
import (
2023-04-29 11:29:29 +08:00
"fmt"
2023-06-29 13:16:42 +08:00
"os"
2023-04-25 18:41:34 +08:00
"testing"
2023-05-24 15:25:31 +08:00
"time"
2023-04-25 18:41:34 +08:00
)
func TestParse(t *testing.T) {
2023-06-30 17:55:45 +08:00
ParseBinlogFile("./test/mysql-bin.000023", func(transaction Transaction) bool {
2023-05-24 15:25:31 +08:00
fmt.Println(transaction)
2023-06-30 17:55:45 +08:00
return true
2023-05-24 15:25:31 +08:00
})
}
func TestParseFilter(t *testing.T) {
ParseBinlogWithFilter("./test/mysql-bin.000023", 0, BinlogFilter{
IncludeGtid: "",
ExcludeGtid: "",
StartPos: 0,
EndPos: 0,
StartDate: time.Time{},
EndDate: time.Time{},
BigThan: 0,
SmallThan: 0,
2023-06-30 17:55:45 +08:00
}, func(transaction Transaction) bool {
2023-04-29 11:29:29 +08:00
fmt.Println(transaction)
2023-06-30 17:55:45 +08:00
return true
2023-04-29 11:29:29 +08:00
})
2023-04-25 18:41:34 +08:00
}
2023-06-29 13:16:42 +08:00
func TestParseExternal(t *testing.T) {
file := `C:\mysql-bin.000001`
if _, err := os.Stat(file); err != nil {
return
}
2023-06-30 17:55:45 +08:00
i := 0
2023-06-29 13:16:42 +08:00
ParseBinlogWithFilter(file, 0, BinlogFilter{
2023-06-30 17:55:45 +08:00
OnlyShowGtid: false,
}, func(transaction Transaction) bool {
2023-06-29 13:16:42 +08:00
fmt.Println(transaction)
2023-06-30 17:55:45 +08:00
i++
if i >= 10 {
return false
}
return true
2023-06-29 13:16:42 +08:00
})
}