Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13546 Fix integration tests source-postgres Mac OS #13872

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ public JsonNode getTunnelConfig(final SshTunnel.TunnelMethod tunnelMethod, final

return Jsons.jsonNode(builderWithSchema
.put("tunnel_method", Jsons.jsonNode(ImmutableMap.builder()
.put("tunnel_host",
Objects.requireNonNull(bastion.getContainerInfo().getNetworkSettings()
.getNetworks()
.get(((Network.NetworkImpl) network).getName())
.getIpAddress()))
.put("tunnel_host", bastion.getHost())
.put("tunnel_method", tunnelMethod)
.put("tunnel_port", bastion.getExposedPorts().get(0))
.put("tunnel_port", bastion.getFirstMappedPort())
.put("tunnel_user", SSH_USER)
.put("tunnel_user_password", tunnelMethod.equals(SSH_PASSWORD_AUTH) ? SSH_PASSWORD : "")
.put("ssh_key", tunnelMethod.equals(SSH_KEY_AUTH) ? bastion.execInContainer("cat", "var/bastion/id_rsa").getStdout() : "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;
import io.airbyte.commons.functional.CheckedFunction;
import io.airbyte.commons.json.Jsons;
import io.airbyte.db.Database;
import io.airbyte.db.factory.DSLContextFactory;
Expand All @@ -25,17 +26,44 @@
import io.airbyte.protocol.models.SyncMode;
import java.util.HashMap;
import java.util.List;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.testcontainers.containers.PostgreSQLContainer;

public abstract class AbstractSshPostgresSourceAcceptanceTest extends SourceAcceptanceTest {

private static final String STREAM_NAME = "public.id_and_name";
private static final String STREAM_NAME2 = "public.starships";
private PostgreSQLContainer<?> db;
private final SshBastionContainer bastion = new SshBastionContainer();
private static JsonNode config;
private final SshBastionContainer bastion = new SshBastionContainer();
private PostgreSQLContainer<?> db;

private static void populateDatabaseTestData() throws Exception {
SshTunnel.sshWrap(
config,
List.of("host"),
List.of("port"),
(CheckedFunction<JsonNode, List<JsonNode>, Exception>) mangledConfig -> getDatabaseFromConfig(mangledConfig)
.query(ctx -> {
ctx.fetch("CREATE TABLE id_and_name(id INTEGER, name VARCHAR(200));");
ctx.fetch("INSERT INTO id_and_name (id, name) VALUES (1,'picard'), (2, 'crusher'), (3, 'vash');");
ctx.fetch("CREATE TABLE starships(id INTEGER, name VARCHAR(200));");
ctx.fetch("INSERT INTO starships (id, name) VALUES (1,'enterprise-d'), (2, 'defiant'), (3, 'yamato');");
return null;
}));
}

private static Database getDatabaseFromConfig(final JsonNode config) {
return new Database(
DSLContextFactory.create(
config.get("username").asText(),
config.get("password").asText(),
DatabaseDriver.POSTGRESQL.getDriverClassName(),
String.format(DatabaseDriver.POSTGRESQL.getUrlFormatString(),
config.get("host").asText(),
config.get("port").asInt(),
config.get("database").asText()),
SQLDialect.POSTGRES));
}

public abstract SshTunnel.TunnelMethod getTunnelMethod();

Expand All @@ -59,28 +87,6 @@ private void initAndStartJdbcContainer() {
db.start();
}

private static void populateDatabaseTestData() throws Exception {
try (final DSLContext dslContext = DSLContextFactory.create(
config.get("username").asText(),
config.get("password").asText(),
DatabaseDriver.POSTGRESQL.getDriverClassName(),
String.format(DatabaseDriver.POSTGRESQL.getUrlFormatString(),
config.get("host").asText(),
config.get("port").asInt(),
config.get("database").asText()),
SQLDialect.POSTGRES)) {
final Database database = new Database(dslContext);

database.query(ctx -> {
ctx.fetch("CREATE TABLE id_and_name(id INTEGER, name VARCHAR(200));");
ctx.fetch("INSERT INTO id_and_name (id, name) VALUES (1,'picard'), (2, 'crusher'), (3, 'vash');");
ctx.fetch("CREATE TABLE starships(id INTEGER, name VARCHAR(200));");
ctx.fetch("INSERT INTO starships (id, name) VALUES (1,'enterprise-d'), (2, 'defiant'), (3, 'yamato');");
return null;
});
}
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
bastion.stopAndCloseContainers(db);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,5 @@ public void testRecordsProducedDuringAndAfterSync() throws Exception {
recordsFromFirstBatchWithoutDuplicates.size() + recordsFromSecondBatchWithoutDuplicates
.size());
}

}