Skip to content

Commit 47a3d3b

Browse files
Fix test
1 parent fc9cbb1 commit 47a3d3b

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

go/base/utils_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package base
77

88
import (
9+
gosql "database/sql"
910
"testing"
1011

1112
"github.com/github/gh-ost/go/mysql"
@@ -17,6 +18,10 @@ func init() {
1718
log.SetLevel(log.ERROR)
1819
}
1920

21+
func newMysqlPort(port int64) gosql.NullInt64 {
22+
return gosql.NullInt64{Int64: port, Valid: port > 0}
23+
}
24+
2025
func TestStringContainsAll(t *testing.T) {
2126
s := `insert,delete,update`
2227

@@ -41,8 +46,8 @@ func TestValidateConnection(t *testing.T) {
4146
{
4247
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
4348
serverInfo := &mysql.ServerInfo{
44-
Port: mysql.NewPort(mysql.DefaultInstancePort),
45-
ExtraPort: mysql.NewPort(mysql.DefaultInstancePort + 1),
49+
Port: newMysqlPort(mysql.DefaultInstancePort),
50+
ExtraPort: newMysqlPort(mysql.DefaultInstancePort + 1),
4651
}
4752
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
4853
}
@@ -77,24 +82,24 @@ func TestValidateConnection(t *testing.T) {
7782
{
7883
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
7984
serverInfo := &mysql.ServerInfo{
80-
ExtraPort: mysql.NewPort(mysql.DefaultInstancePort),
85+
ExtraPort: newMysqlPort(mysql.DefaultInstancePort),
8186
}
8287
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
8388
}
8489
// check extra_port validates when port does not match but extra_port does
8590
{
8691
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
8792
serverInfo := &mysql.ServerInfo{
88-
Port: mysql.NewPort(12345),
89-
ExtraPort: mysql.NewPort(mysql.DefaultInstancePort),
93+
Port: newMysqlPort(12345),
94+
ExtraPort: newMysqlPort(mysql.DefaultInstancePort),
9095
}
9196
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
9297
}
9398
// check validation fails when valid port does not match connectionConfig
9499
{
95100
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
96101
serverInfo := &mysql.ServerInfo{
97-
Port: mysql.NewPort(9999),
102+
Port: newMysqlPort(9999),
98103
}
99104
test.S(t).ExpectNotNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
100105
}

go/mysql/server_info.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,12 @@ package mysql
77

88
import gosql "database/sql"
99

10-
// Port represents a MySQL server port.
11-
type Port *gosql.NullInt64
12-
13-
// NewPort creates a new Port.
14-
func NewPort(port int64) Port {
15-
return Port{Int64: port, Valid: port > 0}
16-
}
17-
1810
// ServerInfo represents the online config of a MySQL server.
1911
type ServerInfo struct {
2012
Version string
2113
VersionComment string
2214
Hostname string
23-
Port Port
15+
Port gosql.NullInt64
2416
BinlogFormat string
2517
BinlogRowImage string
2618
LogBin bool
@@ -29,7 +21,7 @@ type ServerInfo struct {
2921
TimeZone string
3022

3123
// @@global.extra_port is Percona/MariaDB-only
32-
ExtraPort Port
24+
ExtraPort gosql.NullInt64
3325
}
3426

3527
// GetServerInfo returns a ServerInfo struct representing

0 commit comments

Comments
 (0)