Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: make test port allocation more clear (#1384)

Yilong Lia4101c3326ee
diff --git a/tests/tests.go b/tests/tests.go
index c0e33247d2..0a05c64c6b 100644
--- a/tests/tests.go
+++ b/tests/tests.go
@@ -109,35 +109,28 @@ type controller struct {
}
func getTestPort(testName string) int {
- // The port should be incremented by 3 for bytebase, Postgres, and GitLab, unless documented otherwise.
- switch testName {
- case "TestServiceRestart":
- return 1234
- case "TestSchemaAndDataUpdate":
- return 1237
- case "TestVCS":
- return 1240
- case "TestTenant":
- return 1243
- case "TestTenantVCS":
- return 1246
- case "TestTenantDatabaseNameTemplate":
- return 1249
- // TestGhostSchemaUpdate uses 4 ports in total. The additional one is for a MySQL instance.
- case "TestGhostSchemaUpdate":
- return 1252
- case "TestBackupRestoreBasic":
- return 1256
- case "TestPITR":
- return 1259
- case "TestTenantVCSDatabaseNameTemplate":
- return 1262
- case "TestBootWithExternalPg":
- return 1265
- case "TestSheetVCS":
- return 1269
- case "NEXT":
- return 1272
+ // We allocates 4 ports for each of the integration test, who probably would start
+ // the bytebase server, Postgres, MySQL and GitLab.
+ tests := []string{
+ "TestServiceRestart",
+ "TestSchemaAndDataUpdate",
+ "TestVCS",
+ "TestTenant",
+ "TestTenantVCS",
+ "TestTenantDatabaseNameTemplate",
+ "TestGhostSchemaUpdate",
+ "TestBackupRestoreBasic",
+ "TestPITR",
+ "TestTenantVCSDatabaseNameTemplate",
+ "TestBootWithExternalPg",
+ "TestSheetVCS",
+ }
+ port := 1234
+ for _, name := range tests {
+ if testName == name {
+ return port
+ }
+ port += 4
}
panic(fmt.Sprintf("test %q doesn't have assigned port, please set it in getTestPort()", testName))
}