Skip to content

Commit e7ae420

Browse files
Fix port test
1 parent dc4fe50 commit e7ae420

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

go/base/utils_test.go

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

88
import (
9-
gosql "database/sql"
109
"testing"
1110

1211
"github.com/github/gh-ost/go/mysql"
@@ -42,8 +41,8 @@ func TestValidateConnection(t *testing.T) {
4241
{
4342
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
4443
serverInfo := &mysql.ServerInfo{
45-
Port: gosql.NullInt64{Int64: mysql.DefaultInstancePort, Valid: true},
46-
ExtraPort: gosql.NullInt64{Int64: mysql.DefaultInstancePort + 1, Valid: true},
44+
Port: mysql.NewPort(mysql.DefaultInstancePort),
45+
ExtraPort: mysql.NewPort(mysql.DefaultInstancePort + 1),
4746
}
4847
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
4948
}
@@ -78,24 +77,24 @@ func TestValidateConnection(t *testing.T) {
7877
{
7978
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
8079
serverInfo := &mysql.ServerInfo{
81-
ExtraPort: gosql.NullInt64{Int64: mysql.DefaultInstancePort, Valid: true},
80+
ExtraPort: mysql.NewPort(mysql.DefaultInstancePort),
8281
}
8382
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
8483
}
8584
// check extra_port validates when port does not match but extra_port does
8685
{
8786
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
8887
serverInfo := &mysql.ServerInfo{
89-
Port: gosql.NullInt64{Int64: 12345, Valid: true},
90-
ExtraPort: gosql.NullInt64{Int64: mysql.DefaultInstancePort, Valid: true},
88+
Port: mysql.NewPort(12345),
89+
ExtraPort: mysql.NewPort(mysql.DefaultInstancePort),
9190
}
9291
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
9392
}
9493
// check validation fails when valid port does not match connectionConfig
9594
{
9695
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
9796
serverInfo := &mysql.ServerInfo{
98-
Port: gosql.NullInt64{Int64: 9999, Valid: true},
97+
Port: mysql.NewPort(9999),
9998
}
10099
test.S(t).ExpectNotNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
101100
}

go/mysql/server_info.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ import gosql "database/sql"
1111
type Port gosql.NullInt64
1212

1313
// NewPort creates a new Port.
14-
func NewPort(port int64) gosql.NullInt64 {
15-
return gosql.NullInt64{
16-
Int64: port,
17-
Valid: port > 0,
18-
}
14+
func NewPort(port int64) Port {
15+
return Port{Int64: port, Valid: port > 0}
1916
}
2017

2118
// ServerInfo represents the online config of a MySQL server.

0 commit comments

Comments
 (0)