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

🐛 Source Mongo: Fix failing acceptance tests #28816

Merged
merged 10 commits into from
Aug 3, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,14 @@ protected void setupEnvironment(final TestDestinationEnv environment) throws Exc
+ ". Override by setting setting path with the CREDENTIALS_PATH constant.");
}

final String credentialsJsonString = Files.readString(CREDENTIALS_PATH);
final JsonNode credentialsJson = Jsons.deserialize(credentialsJsonString);

final JsonNode instanceConfig = Jsons.jsonNode(ImmutableMap.builder()
.put("instance", MongoInstanceType.ATLAS.getType())
.put("cluster_url", credentialsJson.get("cluster_url").asText())
.build());

config = Jsons.jsonNode(ImmutableMap.builder()
.put("user", credentialsJson.get("user").asText())
.put(JdbcUtils.PASSWORD_KEY, credentialsJson.get(JdbcUtils.PASSWORD_KEY).asText())
.put(INSTANCE_TYPE, instanceConfig)
.put(JdbcUtils.DATABASE_KEY, DATABASE_NAME)
.put("auth_source", "admin")
.build());

final var credentials = String.format("%s:%s@", config.get("user").asText(),
config.get(JdbcUtils.PASSWORD_KEY).asText());
final String connectionString = String.format("mongodb+srv://%s%s/%s?retryWrites=true&w=majority&tls=true",
credentials,
config.get(INSTANCE_TYPE).get("cluster_url").asText(),
config.get(JdbcUtils.DATABASE_KEY).asText());
config = Jsons.deserialize(Files.readString(CREDENTIALS_PATH));
((ObjectNode) config).put(JdbcUtils.DATABASE_KEY, DATABASE_NAME);

final String connectionString = String.format("mongodb+srv://%s:%s@%s/%s?authSource=admin&retryWrites=true&w=majority&tls=true",
config.get("user").asText(),
config.get(JdbcUtils.PASSWORD_KEY).asText(),
config.get("instance_type").get("cluster_url").asText(),
config.get(JdbcUtils.DATABASE_KEY).asText());

database = new MongoDatabase(connectionString, DATABASE_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"properties": {
"instance": {
"type": "string",
"enum": ["standalone"],
"default": "standalone"
"const": "standalone"
},
"host": {
"title": "Host",
Expand All @@ -47,8 +46,7 @@
"properties": {
"instance": {
"type": "string",
"enum": ["replica"],
"default": "replica"
"const": "replica"
},
"server_addresses": {
"title": "Server Addresses",
Expand All @@ -67,13 +65,12 @@
},
{
"title": "MongoDB Atlas",
"additionalProperties": false,
"additionalProperties": true,
"required": ["instance", "cluster_url"],
"properties": {
"instance": {
"type": "string",
"enum": ["atlas"],
"default": "atlas"
"const": "atlas"
},
"cluster_url": {
"title": "Cluster URL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,16 @@ protected void setupEnvironment(final TestDestinationEnv environment) throws Exc
+ ". Override by setting setting path with the CREDENTIALS_PATH constant.");
}

final String credentialsJsonString = Files.readString(CREDENTIALS_PATH);
final JsonNode credentialsJson = Jsons.deserialize(credentialsJsonString);

final JsonNode instanceConfig = Jsons.jsonNode(ImmutableMap.builder()
.put("instance", ATLAS.getType())
.put("cluster_url", credentialsJson.get("cluster_url").asText())
.build());

config = Jsons.jsonNode(ImmutableMap.builder()
.put("user", credentialsJson.get("user").asText())
.put(JdbcUtils.PASSWORD_KEY, credentialsJson.get(JdbcUtils.PASSWORD_KEY).asText())
.put("instance_type", instanceConfig)
.put(JdbcUtils.DATABASE_KEY, DATABASE_NAME)
.put("auth_source", "admin")
.build());
config = Jsons.deserialize(Files.readString(CREDENTIALS_PATH));
((ObjectNode) config).put(JdbcUtils.DATABASE_KEY, DATABASE_NAME);

final String connectionString = String.format("mongodb+srv://%s:%s@%s/%s?authSource=admin&retryWrites=true&w=majority&tls=true",
config.get("user").asText(),
config.get(JdbcUtils.PASSWORD_KEY).asText(),
config.get("instance_type").get("cluster_url").asText(),
config.get(JdbcUtils.DATABASE_KEY).asText());

database = new MongoDatabase(connectionString, DATABASE_NAME);
database = new MongoDatabase(connectionString, config.get(JdbcUtils.DATABASE_KEY).asText());

final MongoCollection<Document> collection = database.createCollection(COLLECTION_NAME);
final var objectDocument = new Document("testObject", new Document("name", "subName").append("testField1", "testField1").append("testInt", 10)
Expand Down Expand Up @@ -134,11 +121,11 @@ public void testCheckIncorrectPassword() throws Exception {

@Test
public void testCheckIncorrectCluster() throws Exception {
((ObjectNode) config).with("instance_type")
.put("cluster_url", "cluster0.iqgf8.mongodb.netfail");
final String badClusterUrl = "cluster0.iqgf8.mongodb.netfail";
config.withObject("/instance_type").put("cluster_url", badClusterUrl);
final AirbyteConnectionStatus status = new MongoDbSource().check(config);
assertEquals(AirbyteConnectionStatus.Status.FAILED, status.getStatus());
assertTrue(status.getMessage().contains("State code: -4"));
assertTrue(status.getMessage().matches("State code: -\\d+.*"));
}

@Test
Expand Down