diff --git a/go/base/utils_test.go b/go/base/utils_test.go index 9c8ce3f..fa3a07e 100644 --- a/go/base/utils_test.go +++ b/go/base/utils_test.go @@ -6,6 +6,7 @@ package base import ( + gosql "database/sql" "testing" "github.com/github/gh-ost/go/mysql" @@ -17,6 +18,10 @@ func init() { log.SetLevel(log.ERROR) } +func newMysqlPort(port int64) gosql.NullInt64 { + return gosql.NullInt64{Int64: port, Valid: port > 0} +} + func TestStringContainsAll(t *testing.T) { s := `insert,delete,update` @@ -41,8 +46,8 @@ func TestValidateConnection(t *testing.T) { { migrationContext := &MigrationContext{Log: NewDefaultLogger()} serverInfo := &mysql.ServerInfo{ - Port: mysql.NewPort(mysql.DefaultInstancePort), - ExtraPort: mysql.NewPort(mysql.DefaultInstancePort + 1), + Port: newMysqlPort(mysql.DefaultInstancePort), + ExtraPort: newMysqlPort(mysql.DefaultInstancePort + 1), } test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test")) } @@ -77,7 +82,7 @@ func TestValidateConnection(t *testing.T) { { migrationContext := &MigrationContext{Log: NewDefaultLogger()} serverInfo := &mysql.ServerInfo{ - ExtraPort: mysql.NewPort(mysql.DefaultInstancePort), + ExtraPort: newMysqlPort(mysql.DefaultInstancePort), } test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test")) } @@ -85,8 +90,8 @@ func TestValidateConnection(t *testing.T) { { migrationContext := &MigrationContext{Log: NewDefaultLogger()} serverInfo := &mysql.ServerInfo{ - Port: mysql.NewPort(12345), - ExtraPort: mysql.NewPort(mysql.DefaultInstancePort), + Port: newMysqlPort(12345), + ExtraPort: newMysqlPort(mysql.DefaultInstancePort), } test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test")) } @@ -94,7 +99,7 @@ func TestValidateConnection(t *testing.T) { { migrationContext := &MigrationContext{Log: NewDefaultLogger()} serverInfo := &mysql.ServerInfo{ - Port: mysql.NewPort(9999), + Port: newMysqlPort(9999), } test.S(t).ExpectNotNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test")) } diff --git a/go/mysql/server_info.go b/go/mysql/server_info.go index 1a0db30..c4e3e37 100644 --- a/go/mysql/server_info.go +++ b/go/mysql/server_info.go @@ -7,20 +7,12 @@ package mysql import gosql "database/sql" -// Port represents a MySQL server port. -type Port *gosql.NullInt64 - -// NewPort creates a new Port. -func NewPort(port int64) Port { - return Port{Int64: port, Valid: port > 0} -} - // ServerInfo represents the online config of a MySQL server. type ServerInfo struct { Version string VersionComment string Hostname string - Port Port + Port gosql.NullInt64 BinlogFormat string BinlogRowImage string LogBin bool @@ -29,7 +21,7 @@ type ServerInfo struct { TimeZone string // @@global.extra_port is Percona/MariaDB-only - ExtraPort Port + ExtraPort gosql.NullInt64 } // GetServerInfo returns a ServerInfo struct representing