This commit is contained in:
Tim Vaillancourt 2023-01-17 22:59:00 +01:00
parent fc9cbb17cc
commit 47a3d3b22d
2 changed files with 13 additions and 16 deletions

View File

@ -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"))
}

View File

@ -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