Skip to content

Commit 3bb89a2

Browse files
Add test
1 parent d1ca1de commit 3bb89a2

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

go/base/utils_test.go

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/*
2-
Copyright 2016 GitHub Inc.
2+
Copyright 2022 GitHub Inc.
33
See https://github.com/github/gh-ost/blob/master/LICENSE
44
*/
55

66
package base
77

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

12+
"github.com/github/gh-ost/go/mysql"
1113
"github.com/openark/golib/log"
1214
test "github.com/openark/golib/tests"
1315
)
@@ -27,3 +29,67 @@ func TestStringContainsAll(t *testing.T) {
2729
test.S(t).ExpectTrue(StringContainsAll(s, "insert", ""))
2830
test.S(t).ExpectTrue(StringContainsAll(s, "insert", "update", "delete"))
2931
}
32+
33+
func TestValidateConnection(t *testing.T) {
34+
connectionConfig := &mysql.ConnectionConfig{
35+
Key: mysql.InstanceKey{
36+
Hostname: t.Name(),
37+
Port: mysql.DefaultInstancePort,
38+
},
39+
}
40+
// check valid port matches on plain mysql
41+
{
42+
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
43+
serverInfo := &mysql.ServerInfo{
44+
Port: gosql.NullInt64{Int64: mysql.DefaultInstancePort, Valid: true},
45+
}
46+
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
47+
}
48+
// check NULL port validates when AliyunRDS=true
49+
{
50+
migrationContext := &MigrationContext{
51+
Log: NewDefaultLogger(),
52+
AliyunRDS: true,
53+
}
54+
serverInfo := &mysql.ServerInfo{
55+
Port: gosql.NullInt64{Int64: 0, Valid: false},
56+
}
57+
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
58+
}
59+
// check NULL port validates when AzureMySQL=true
60+
{
61+
migrationContext := &MigrationContext{
62+
Log: NewDefaultLogger(),
63+
AzureMySQL: true,
64+
}
65+
serverInfo := &mysql.ServerInfo{
66+
Port: gosql.NullInt64{Int64: 0, Valid: false},
67+
}
68+
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
69+
}
70+
// check NULL port validates when GoogleCloudPlatform=true
71+
{
72+
migrationContext := &MigrationContext{
73+
Log: NewDefaultLogger(),
74+
GoogleCloudPlatform: true,
75+
}
76+
serverInfo := &mysql.ServerInfo{
77+
Port: gosql.NullInt64{Int64: 0, Valid: false},
78+
}
79+
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
80+
}
81+
// check extra_port validates when port=NULL
82+
{
83+
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
84+
serverInfo := &mysql.ServerInfo{
85+
ExtraPort: gosql.NullInt64{Int64: mysql.DefaultInstancePort, Valid: true},
86+
}
87+
test.S(t).ExpectNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
88+
}
89+
// check validation fails when port and extra_port are invalid
90+
{
91+
migrationContext := &MigrationContext{Log: NewDefaultLogger()}
92+
serverInfo := &mysql.ServerInfo{}
93+
test.S(t).ExpectNotNil(ValidateConnection(serverInfo, connectionConfig, migrationContext, "test"))
94+
}
95+
}

go/logic/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func (this *Inspector) validateBinlogs() error {
369369
this.migrationContext.Log.Infof("%s has %s binlog_format. I will change it to ROW, and will NOT change it back, even in the event of failure.", this.connectionConfig.Key.String(), this.ServerInfo().BinlogFormat)
370370
}
371371

372-
if this.ServerInfo().BinlogRowImage != "FULL" {
372+
if strings.ToUpper(this.ServerInfo().BinlogRowImage) != "FULL" {
373373
return fmt.Errorf("%s has '%s' binlog_row_image, and only 'FULL' is supported. This operation cannot proceed. You may `set global binlog_row_image='full'` and try again", this.connectionConfig.Key.String(), this.ServerInfo().BinlogRowImage)
374374
}
375375

0 commit comments

Comments
 (0)