Skip to content

Commit

Permalink
🐛 Source Mongo: Fix failing acceptance tests (#28816)
Browse files Browse the repository at this point in the history
* Fix failing acceptance tests

* Fix failing strict acceptance tests
  • Loading branch information
jdpgrailsdev authored and jbfbell committed Aug 5, 2023
1 parent 7aaafdd commit ef95c9b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 48 deletions.
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

0 comments on commit ef95c9b

Please sign in to comment.