Skip to content

Commit d117085

Browse files
lnxsiddontang
authored andcommitted
Add tests for normalize method (go-mysql-org#226)
1 parent 3833c32 commit d117085

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mysql/mysql_gtid.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ func (s IntervalSlice) Normalize() IntervalSlice {
9797
n = append(n, s[i])
9898
continue
9999
} else {
100-
n[len(n)-1] = Interval{last.Start, s[i].Stop}
100+
stop := s[i].Stop
101+
if last.Stop > stop {
102+
stop = last.Stop
103+
}
104+
n[len(n)-1] = Interval{last.Start, stop}
101105
}
102106
}
103107

mysql/mysql_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ func (t *mysqlTestSuite) TestMysqlGTIDIntervalSlice(c *check.C) {
6060
n = i.Normalize()
6161
c.Assert(n, check.DeepEquals, IntervalSlice{Interval{1, 3}, Interval{4, 5}})
6262

63+
i = IntervalSlice{Interval{1, 4}, Interval{2, 3}}
64+
i.Sort()
65+
c.Assert(i, check.DeepEquals, IntervalSlice{Interval{1, 4}, Interval{2, 3}})
66+
n = i.Normalize()
67+
c.Assert(n, check.DeepEquals, IntervalSlice{Interval{1, 4}})
68+
6369
n1 := IntervalSlice{Interval{1, 3}, Interval{4, 5}}
6470
n2 := IntervalSlice{Interval{1, 2}}
6571

0 commit comments

Comments
 (0)