From d41bb1d56f40f950d9100f06ef7bacb47cc7a376 Mon Sep 17 00:00:00 2001
From: atercattus <cat@ater.me>
Date: Thu, 8 Apr 2021 09:53:46 +0300
Subject: [PATCH] Replace magic numbers in canal/canal_test.go by constants

---
 canal/canal_test.go | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
 mode change 100755 => 100644 canal/canal_test.go

diff --git a/canal/canal_test.go b/canal/canal_test.go
old mode 100755
new mode 100644
index ea452f033..49dc72fb6
--- a/canal/canal_test.go
+++ b/canal/canal_test.go
@@ -26,6 +26,16 @@ type canalTestSuite struct {
 
 var _ = Suite(&canalTestSuite{})
 
+const (
+	miA = 0
+	miB = -1
+	miC = 1
+
+	umiA = 0
+	umiB = 1
+	umiC = 16777215
+)
+
 func (s *canalTestSuite) SetUpSuite(c *C) {
 	cfg := NewDefaultConfig()
 	cfg.Addr = fmt.Sprintf("%s:3306", *testHost)
@@ -62,7 +72,11 @@ func (s *canalTestSuite) SetUpSuite(c *C) {
 	s.execute(c, sql)
 
 	s.execute(c, "DELETE FROM test.canal_test")
-	s.execute(c, "INSERT INTO test.canal_test (content, name, mi, umi) VALUES (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?)", "1", "a", 0, 0, `\0\ndsfasdf`, "b", 1, 16777215, "", "c", -1, 1)
+	s.execute(c, "INSERT INTO test.canal_test (content, name, mi, umi) VALUES (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?)",
+		"1", "a", miA, umiA,
+		`\0\ndsfasdf`, "b", miC, umiC,
+		"", "c", miB, umiB,
+	)
 
 	s.execute(c, "SET GLOBAL binlog_format = 'ROW'")
 
@@ -99,7 +113,7 @@ type testEventHandler struct {
 func (h *testEventHandler) OnRow(e *RowsEvent) error {
 	log.Infof("OnRow %s %v\n", e.Action, e.Rows)
 	umi, ok := e.Rows[0][4].(uint32) // 4th col is umi. mysqldump gives uint64 instead of uint32
-	if ok && (umi != 0 && umi != 1 && umi != 16777215) {
+	if ok && (umi != umiA && umi != umiB && umi != umiC) {
 		return fmt.Errorf("invalid unsigned medium int %d", umi)
 	}
 	return nil
@@ -119,7 +133,11 @@ func (s *canalTestSuite) TestCanal(c *C) {
 	for i := 1; i < 10; i++ {
 		s.execute(c, "INSERT INTO test.canal_test (name) VALUES (?)", fmt.Sprintf("%d", i))
 	}
-	s.execute(c, "INSERT INTO test.canal_test (mi,umi) VALUES (?,?), (?,?), (?,?)", 0, 0, -1, 16777215, 1, 1)
+	s.execute(c, "INSERT INTO test.canal_test (mi,umi) VALUES (?,?), (?,?), (?,?)",
+		miA, umiA,
+		miC, umiC,
+		miB, umiB,
+	)
 	s.execute(c, "ALTER TABLE test.canal_test ADD `age` INT(5) NOT NULL AFTER `name`")
 	s.execute(c, "INSERT INTO test.canal_test (name,age) VALUES (?,?)", "d", "18")