Skip to content

Commit

Permalink
Tweak the testcontainers setup (#1460)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
arthurschreiber and meiji163 authored Nov 18, 2024
1 parent a6ccd3f commit 42c0f08
Show file tree
Hide file tree
Showing 15 changed files with 788 additions and 131 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.34.0
golang.org/x/net v0.24.0
golang.org/x/sync v0.8.0
golang.org/x/term v0.19.0
golang.org/x/text v0.14.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
5 changes: 5 additions & 0 deletions go/base/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ type MigrationContext struct {
AzureMySQL bool
AttemptInstantDDL bool

// SkipPortValidation allows skipping the port validation in `ValidateConnection`
// This is useful when connecting to a MySQL instance where the external port
// may not match the internal port.
SkipPortValidation bool

config ContextConfig
configMutex *sync.Mutex
ConfigFile string
Expand Down
11 changes: 10 additions & 1 deletion go/base/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,27 @@ func StringContainsAll(s string, substrings ...string) bool {

func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext, name string) (string, error) {
versionQuery := `select @@global.version`
var port, extraPort int

var version string
if err := db.QueryRow(versionQuery).Scan(&version); err != nil {
return "", err
}

if migrationContext.SkipPortValidation {
return version, nil
}

var extraPort int

extraPortQuery := `select @@global.extra_port`
if err := db.QueryRow(extraPortQuery).Scan(&extraPort); err != nil { //nolint:staticcheck
// swallow this error. not all servers support extra_port
}

// AliyunRDS set users port to "NULL", replace it by gh-ost param
// GCP set users port to "NULL", replace it by gh-ost param
// Azure MySQL set users port to a different value by design, replace it by gh-ost para
var port int
if migrationContext.AliyunRDS || migrationContext.GoogleCloudPlatform || migrationContext.AzureMySQL {
port = connectionConfig.Key.Port
} else {
Expand Down
Loading

0 comments on commit 42c0f08

Please sign in to comment.