Skip to content

Commit

Permalink
feat(ci): complete test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sinomoe committed Nov 8, 2024
1 parent 31202c5 commit 7c5a140
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
echo -n "mysqldump -V: " ; mysqldump -V
echo -e '[mysqld]\nserver-id=1\nlog-bin=mysql\nbinlog-format=row\ngtid-mode=ON\nenforce_gtid_consistency=ON\n' | sudo tee /etc/mysql/conf.d/replication.cnf
# bind to :: for dual-stack listening
sudo sed -i 's/bind-address.*= 127.0.0.1/bind-address = ::/' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo sed -i 's/mysqlx-bind-address.*= 127.0.0.1/mysqlx-bind-address = ::/' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo service mysql start
# apply this for mysql5 & mysql8 compatibility
Expand Down Expand Up @@ -109,5 +114,6 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: Build on ${{ matrix.os }}/${{ matrix.arch }}
run: GOARCH=${{ matrix.arch }} GOOS=${{ matrix.os }} go build ./...
23 changes: 22 additions & 1 deletion canal/canal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,30 @@ import (
)

type canalTestSuite struct {
addr string
suite.Suite
c *Canal
}

type canalTestSuiteOption func(c *canalTestSuite)

func withAddr(addr string) canalTestSuiteOption {
return func(c *canalTestSuite) {
c.addr = addr
}
}

func newCanalTestSuite(opts ...canalTestSuiteOption) *canalTestSuite {
c := new(canalTestSuite)
for _, opt := range opts {
opt(c)
}
return c
}

func TestCanalSuite(t *testing.T) {
suite.Run(t, new(canalTestSuite))
suite.Run(t, newCanalTestSuite())
suite.Run(t, newCanalTestSuite(withAddr(mysql.DEFAULT_IPV6_ADDR)))
}

const (
Expand All @@ -37,6 +55,9 @@ const (
func (s *canalTestSuite) SetupSuite() {
cfg := NewDefaultConfig()
cfg.Addr = fmt.Sprintf("%s:%s", *test_util.MysqlHost, *test_util.MysqlPort)
if s.addr != "" {
cfg.Addr = s.addr
}
cfg.User = "root"
cfg.HeartbeatPeriod = 200 * time.Millisecond
cfg.ReadTimeout = 300 * time.Millisecond
Expand Down
1 change: 1 addition & 0 deletions mysql/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const (

const (
DEFAULT_ADDR = "127.0.0.1:3306"
DEFAULT_IPV6_ADDR = "[::1]:3306"
DEFAULT_USER = "root"
DEFAULT_PASSWORD = ""
DEFAULT_FLAVOR = "mysql"
Expand Down

0 comments on commit 7c5a140

Please sign in to comment.