Skip to content

Commit 42c0f08

Browse files
Tweak the testcontainers setup (#1460)
* Allow skipping port validation in tests. * Add more test coverage. * Fix linter. * Fix DSN string generation. * Add a `Migrator` test. * Add a tmp folder. * Make the linter happy. * Add tests for `Streamer`. * Close the `Streamer`. * Fix linter issue. * ignore contextcheck linter --------- Co-authored-by: meiji163 <meiji163@github.com>
1 parent a6ccd3f commit 42c0f08

File tree

15 files changed

+788
-131
lines changed

15 files changed

+788
-131
lines changed

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/stretchr/testify v1.9.0
1212
github.com/testcontainers/testcontainers-go v0.34.0
1313
golang.org/x/net v0.24.0
14+
golang.org/x/sync v0.8.0
1415
golang.org/x/term v0.19.0
1516
golang.org/x/text v0.14.0
1617
)

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
199199
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
200200
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
201201
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
202+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
203+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
202204
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
203205
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
204206
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

Diff for: go/base/context.go

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ type MigrationContext struct {
103103
AzureMySQL bool
104104
AttemptInstantDDL bool
105105

106+
// SkipPortValidation allows skipping the port validation in `ValidateConnection`
107+
// This is useful when connecting to a MySQL instance where the external port
108+
// may not match the internal port.
109+
SkipPortValidation bool
110+
106111
config ContextConfig
107112
configMutex *sync.Mutex
108113
ConfigFile string

Diff for: go/base/utils.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,27 @@ func StringContainsAll(s string, substrings ...string) bool {
6363

6464
func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext, name string) (string, error) {
6565
versionQuery := `select @@global.version`
66-
var port, extraPort int
66+
6767
var version string
6868
if err := db.QueryRow(versionQuery).Scan(&version); err != nil {
6969
return "", err
7070
}
71+
72+
if migrationContext.SkipPortValidation {
73+
return version, nil
74+
}
75+
76+
var extraPort int
77+
7178
extraPortQuery := `select @@global.extra_port`
7279
if err := db.QueryRow(extraPortQuery).Scan(&extraPort); err != nil { //nolint:staticcheck
7380
// swallow this error. not all servers support extra_port
7481
}
82+
7583
// AliyunRDS set users port to "NULL", replace it by gh-ost param
7684
// GCP set users port to "NULL", replace it by gh-ost param
7785
// Azure MySQL set users port to a different value by design, replace it by gh-ost para
86+
var port int
7887
if migrationContext.AliyunRDS || migrationContext.GoogleCloudPlatform || migrationContext.AzureMySQL {
7988
port = connectionConfig.Key.Port
8089
} else {

0 commit comments

Comments
 (0)