You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplify getSharedMySQLContainer - always use environment variables as source of truth
TestMain always sets MYSQL_ENDPOINT, MYSQL_USERNAME, and MYSQL_PASSWORD
for both MySQL and TiDB tests. Use these environment variables as the
primary source of truth, with sharedContainer as an optimization when
available.
// Validate that the provided image matches DOCKER_IMAGE (if provided)
198
-
ifimage!=""&&image!=dockerImage {
199
-
t.Fatalf("ERROR: getSharedMySQLContainer called with image '%s' but DOCKER_IMAGE is set to '%s'.\n"+
200
-
"Remove the hardcoded image parameter - TestMain uses DOCKER_IMAGE env var to create the shared container.",
201
-
image, dockerImage)
204
+
// For MySQL/Percona/MariaDB, TestMain should have set MYSQL_ENDPOINT
205
+
// Use environment variables as the source of truth (TestMain always sets these)
206
+
endpoint:=os.Getenv("MYSQL_ENDPOINT")
207
+
ifendpoint=="" {
208
+
t.Fatalf("ERROR: MYSQL_ENDPOINT not set. TestMain should have set this using DOCKER_IMAGE='%s'.\n"+
209
+
"This indicates TestMain did not run or failed to initialize.", dockerImage)
202
210
}
203
211
204
-
// TestMain should have already created sharedContainer
205
-
// If it's nil, fall back to using environment variables (TestMain sets these)
206
-
ifsharedContainer==nil {
207
-
endpoint:=os.Getenv("MYSQL_ENDPOINT")
208
-
ifendpoint=="" {
209
-
t.Fatalf("ERROR: sharedContainer is nil and MYSQL_ENDPOINT is not set. TestMain should have created the container or set environment variables using DOCKER_IMAGE='%s'.\n"+
210
-
"This indicates a problem with TestMain initialization.", dockerImage)
211
-
}
212
-
// Fallback: use environment variables set by TestMain
213
-
return&MySQLTestContainer{
214
-
Container: nil, // Not available, but tests use environment variables
215
-
Endpoint: endpoint,
216
-
Username: os.Getenv("MYSQL_USERNAME"),
217
-
Password: os.Getenv("MYSQL_PASSWORD"),
218
-
}
212
+
// If sharedContainer is available, use it; otherwise use environment variables
213
+
ifsharedContainer!=nil {
214
+
returnsharedContainer
219
215
}
220
216
221
-
returnsharedContainer
217
+
// Fallback: use environment variables set by TestMain
218
+
// This handles cases where sharedContainer might be nil but environment variables are set
219
+
return&MySQLTestContainer{
220
+
Container: nil, // Not available, but tests use environment variables
221
+
Endpoint: endpoint,
222
+
Username: os.Getenv("MYSQL_USERNAME"),
223
+
Password: os.Getenv("MYSQL_PASSWORD"),
224
+
}
222
225
}
223
226
224
227
// startSharedMySQLContainer starts a shared MySQL container without requiring a testing.T
0 commit comments