Skip to content

Commit 2eb46b6

Browse files
committed
Fix TiDB tests - make getSharedMySQLContainer work for TiDB mode
For TiDB tests, TestMain already sets up the cluster and environment variables. Make getSharedMySQLContainer validate the environment is ready and return a dummy container that uses the environment variables, rather than failing.
1 parent 62fdabf commit 2eb46b6

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

mysql/testcontainers_helper.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ func contains(s, substr string) bool {
162162
// getSharedMySQLContainer returns the shared MySQL container set up by TestMain
163163
// The image parameter is ignored - TestMain uses DOCKER_IMAGE env var
164164
// This function validates that DOCKER_IMAGE is set and fails early if not
165+
// For TiDB tests, TestMain already sets up the cluster and environment variables,
166+
// so this function just validates the environment is ready
165167
func getSharedMySQLContainer(t *testing.T, image string) *MySQLTestContainer {
166168
// Validate that DOCKER_IMAGE is set (required by TestMain)
167169
// This validation must always be present - fail early if DOCKER_IMAGE is empty
@@ -174,11 +176,22 @@ func getSharedMySQLContainer(t *testing.T, image string) *MySQLTestContainer {
174176
"The 'image' parameter to getSharedMySQLContainer is ignored - use DOCKER_IMAGE env var instead.")
175177
}
176178

177-
// Check if we're in TiDB mode - if so, this function shouldn't be called
178-
// TiDB tests use sharedTiDBCluster, not sharedContainer
179+
// Check if we're in TiDB mode
180+
// For TiDB, TestMain already set up the cluster and environment variables
181+
// Just validate that the environment variables are set and return a dummy container
179182
if strings.HasPrefix(dockerImage, "tidb:") {
180-
t.Fatalf("ERROR: getSharedMySQLContainer called but DOCKER_IMAGE is set to '%s' (TiDB format). "+
181-
"TiDB tests should use the shared TiDB cluster from TestMain, not getSharedMySQLContainer.", dockerImage)
183+
// Validate that TestMain set up the environment variables
184+
endpoint := os.Getenv("MYSQL_ENDPOINT")
185+
if endpoint == "" {
186+
t.Fatalf("ERROR: MYSQL_ENDPOINT not set. TestMain should have set this for TiDB cluster.")
187+
}
188+
// Return a dummy container - tests will use environment variables set by TestMain
189+
return &MySQLTestContainer{
190+
Container: nil, // Not used for TiDB
191+
Endpoint: endpoint,
192+
Username: os.Getenv("MYSQL_USERNAME"),
193+
Password: os.Getenv("MYSQL_PASSWORD"),
194+
}
182195
}
183196

184197
// Validate that the provided image matches DOCKER_IMAGE (if provided)

0 commit comments

Comments
 (0)