Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
timvaillancourt committed Jan 17, 2023
1 parent fc9cbb1 commit 47a3d3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
17 changes: 11 additions & 6 deletions go/base/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package base

import (
gosql "database/sql"
"testing"

"github.com/github/gh-ost/go/mysql"
Expand All @@ -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`

Expand All @@ -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"))
}
Expand Down Expand Up @@ -77,24 +82,24 @@ 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"))
}
// check extra_port validates when port does not match but extra_port does
{
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"))
}
// check validation fails when valid port does not match connectionConfig
{
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
serverInfo := &mysql.ServerInfo{
Port: mysql.NewPort(9999),
Port: newMysqlPort(9999),
}
test.S(t).ExpectNotNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
}
Expand Down
12 changes: 2 additions & 10 deletions go/mysql/server_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 47a3d3b

Please sign in to comment.