2016-03-22 14:12:51 +00:00
|
|
|
/*
|
2016-03-24 14:11:56 +00:00
|
|
|
Copyright 2016 GitHub Inc.
|
2016-05-16 09:09:17 +00:00
|
|
|
See https://github.com/github/gh-ost/blob/master/LICENSE
|
2016-03-22 14:12:51 +00:00
|
|
|
*/
|
|
|
|
|
2016-06-18 19:12:07 +00:00
|
|
|
package mysql
|
2016-03-22 14:12:51 +00:00
|
|
|
|
|
|
|
import (
|
2016-03-24 13:25:52 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-06-24 18:19:37 +00:00
|
|
|
"github.com/openark/golib/log"
|
|
|
|
test "github.com/openark/golib/tests"
|
2016-03-22 14:12:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
log.SetLevel(log.ERROR)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBinlogCoordinates(t *testing.T) {
|
|
|
|
c1 := BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: 104}
|
|
|
|
c2 := BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: 104}
|
|
|
|
c3 := BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: 5000}
|
|
|
|
c4 := BinlogCoordinates{LogFile: "mysql-bin.00112", LogPos: 104}
|
|
|
|
|
|
|
|
test.S(t).ExpectTrue(c1.Equals(&c2))
|
|
|
|
test.S(t).ExpectFalse(c1.Equals(&c3))
|
|
|
|
test.S(t).ExpectFalse(c1.Equals(&c4))
|
|
|
|
test.S(t).ExpectFalse(c1.SmallerThan(&c2))
|
|
|
|
test.S(t).ExpectTrue(c1.SmallerThan(&c3))
|
|
|
|
test.S(t).ExpectTrue(c1.SmallerThan(&c4))
|
|
|
|
test.S(t).ExpectTrue(c3.SmallerThan(&c4))
|
|
|
|
test.S(t).ExpectFalse(c3.SmallerThan(&c2))
|
|
|
|
test.S(t).ExpectFalse(c4.SmallerThan(&c2))
|
|
|
|
test.S(t).ExpectFalse(c4.SmallerThan(&c3))
|
|
|
|
|
|
|
|
test.S(t).ExpectTrue(c1.SmallerThanOrEquals(&c2))
|
|
|
|
test.S(t).ExpectTrue(c1.SmallerThanOrEquals(&c3))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBinlogCoordinatesAsKey(t *testing.T) {
|
|
|
|
m := make(map[BinlogCoordinates]bool)
|
|
|
|
|
|
|
|
c1 := BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: 104}
|
|
|
|
c2 := BinlogCoordinates{LogFile: "mysql-bin.00022", LogPos: 104}
|
|
|
|
c3 := BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: 104}
|
|
|
|
c4 := BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: 222}
|
|
|
|
|
|
|
|
m[c1] = true
|
|
|
|
m[c2] = true
|
|
|
|
m[c3] = true
|
|
|
|
m[c4] = true
|
|
|
|
|
|
|
|
test.S(t).ExpectEquals(len(m), 3)
|
|
|
|
}
|