You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.9 KiB
Go
48 lines
1.9 KiB
Go
2 years ago
|
package binlog
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"os/exec"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestDumpBinlogFromPos0(t *testing.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) {
|
||
|
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) {
|
||
|
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) {
|
||
|
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)
|
||
|
}
|
||
|
}
|