Skip to content

Commit 6002b02

Browse files
author
Marius Posta
committed
source-mysql: add and adopt TestDatabaseWithInvalidDatabaseName
1 parent fa66dc8 commit 6002b02

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

airbyte-integrations/connectors/source-mysql/src/test/java/io/airbyte/integrations/source/mysql/CdcMysqlSourceWithSpecialDbNameTest.java

+22-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,34 @@
66

77
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;
88
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.ContainerModifier;
9+
import org.testcontainers.containers.MySQLContainer;
910

1011
public class CdcMysqlSourceWithSpecialDbNameTest extends CdcMysqlSourceTest {
1112

12-
public static final String INVALID_DB_NAME = "invalid@name";
13-
1413
@Override
1514
protected MySQLTestDatabase createTestDatabase() {
16-
return MySQLTestDatabase.inWithDbName(BaseImage.MYSQL_8, INVALID_DB_NAME, ContainerModifier.INVALID_TIMEZONE_CEST, ContainerModifier.CUSTOM_NAME)
15+
var container = new MySQLContainerFactory().shared(
16+
BaseImage.MYSQL_8.reference,
17+
ContainerModifier.INVALID_TIMEZONE_CEST.methodName,
18+
ContainerModifier.CUSTOM_NAME.methodName);
19+
return new TestDatabaseWithInvalidDatabaseName(container)
20+
.initialized()
1721
.withCdcPermissions();
1822
}
1923

24+
static class TestDatabaseWithInvalidDatabaseName extends MySQLTestDatabase {
25+
26+
public static final String INVALID_DB_NAME = "invalid@name";
27+
28+
public TestDatabaseWithInvalidDatabaseName(MySQLContainer<?> container) {
29+
super(container);
30+
}
31+
32+
@Override
33+
public String getDatabaseName() {
34+
return INVALID_DB_NAME;
35+
}
36+
37+
}
38+
2039
}

airbyte-integrations/connectors/source-mysql/src/testFixtures/java/io/airbyte/integrations/source/mysql/MySQLTestDatabase.java

-29
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ static public MySQLTestDatabase in(BaseImage baseImage, ContainerModifier... met
5454
return new MySQLTestDatabase(container).initialized();
5555
}
5656

57-
static public MySQLTestDatabase inWithDbName(BaseImage baseImage, String dbName, ContainerModifier... methods) {
58-
String[] methodNames = Stream.of(methods).map(im -> im.methodName).toList().toArray(new String[0]);
59-
final var container = new MySQLContainerFactory().shared(baseImage.reference, methodNames);
60-
MySQLTestDatabase db = new MySQLTestDatabase(container);
61-
db.setDatabaseName(dbName);
62-
db.initialized();
63-
return db;
64-
}
65-
6657
public MySQLTestDatabase(MySQLContainer<?> container) {
6758
super(container);
6859
}
@@ -80,26 +71,6 @@ public MySQLTestDatabase withoutStrictMode() {
8071
}
8172

8273
static private final int MAX_CONNECTIONS = 1000;
83-
private String databaseName = "";
84-
85-
@Override
86-
public String getDatabaseName() {
87-
if (databaseName.isBlank()) {
88-
return super.getDatabaseName();
89-
} else {
90-
return databaseName;
91-
}
92-
}
93-
94-
@Override
95-
public void close() {
96-
super.close();
97-
databaseName = "";
98-
}
99-
100-
public void setDatabaseName(final String databaseName) {
101-
this.databaseName = databaseName;
102-
}
10374

10475
@Override
10576
protected Stream<Stream<String>> inContainerBootstrapCmd() {

0 commit comments

Comments
 (0)