Skip to content

Commit 2396bb2

Browse files
committed
Ensure DOCKER_IMAGE validation always runs first
Move DOCKER_IMAGE validation before TiDB check so validation always happens. This ensures we fail early if DOCKER_IMAGE is missing, regardless of mode.
1 parent f82e69a commit 2396bb2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

mysql/testcontainers_helper.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,23 @@ func contains(s, substr string) bool {
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
165165
func getSharedMySQLContainer(t *testing.T, image string) *MySQLTestContainer {
166-
// Check if we're in TiDB mode - if so, this function shouldn't be called
167-
tidbVersion := os.Getenv("TIDB_VERSION")
168-
if tidbVersion != "" {
169-
t.Fatalf("ERROR: getSharedMySQLContainer called but TIDB_VERSION is set. " +
170-
"TiDB tests should use the shared TiDB cluster from TestMain, not getSharedMySQLContainer.")
171-
}
172-
173166
// Validate that DOCKER_IMAGE is set (required by TestMain for MySQL/Percona/MariaDB)
167+
// This validation must always be present - fail early if DOCKER_IMAGE is empty
174168
dockerImage := os.Getenv("DOCKER_IMAGE")
175169
if dockerImage == "" {
176170
t.Fatalf("ERROR: DOCKER_IMAGE environment variable is not set. This is required for MySQL/Percona/MariaDB tests.\n" +
177171
"Please set DOCKER_IMAGE to the appropriate Docker image (e.g., mysql:5.6, percona:8.0, mariadb:10.10)\n" +
178172
"The 'image' parameter to getSharedMySQLContainer is ignored - use DOCKER_IMAGE env var instead.")
179173
}
180174

175+
// Check if we're in TiDB mode - if so, this function shouldn't be called
176+
// TiDB tests use sharedTiDBCluster, not sharedContainer
177+
tidbVersion := os.Getenv("TIDB_VERSION")
178+
if tidbVersion != "" {
179+
t.Fatalf("ERROR: getSharedMySQLContainer called but TIDB_VERSION is set. " +
180+
"TiDB tests should use the shared TiDB cluster from TestMain, not getSharedMySQLContainer.")
181+
}
182+
181183
// Validate that the provided image matches DOCKER_IMAGE (if provided)
182184
if image != "" && image != dockerImage {
183185
t.Fatalf("ERROR: getSharedMySQLContainer called with image '%s' but DOCKER_IMAGE is set to '%s'.\n"+

0 commit comments

Comments
 (0)