Skip to content

Commit

Permalink
test: add integration test for named connectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
hessjcg committed Nov 7, 2023
1 parent 1bb166a commit ef9adf1
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2020 Google LLC
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -44,12 +44,12 @@
@RunWith(JUnit4.class)
public class JdbcPostgresNamedConnectorIntegrationTests {

private static final String CONNECTION_NAME = System.getenv("POSTGRES_CONNECTION_NAME");
private static final String CONNECTION_NAME = System.getenv("POSTGRES_IAM_CONNECTION_NAME");
private static final String DB_NAME = System.getenv("POSTGRES_DB");
private static final String DB_USER = System.getenv("POSTGRES_USER");
private static final String DB_USER = System.getenv("POSTGRES_IAM_USER");
private static final ImmutableList<String> requiredEnvVars =
ImmutableList.of("POSTGRES_USER", "POSTGRES_PASS", "POSTGRES_DB", "POSTGRES_CONNECTION_NAME");
@Rule public Timeout globalTimeout = new Timeout(30, TimeUnit.SECONDS);
ImmutableList.of("POSTGRES_IAM_USER", "POSTGRES_DB", "POSTGRES_IAM_CONNECTION_NAME");
@Rule public Timeout globalTimeout = new Timeout(60, TimeUnit.SECONDS);

private HikariDataSource connectionPool;

Expand Down Expand Up @@ -83,16 +83,16 @@ public void setUpPool() throws SQLException {
String jdbcURL = String.format("jdbc:postgresql:///%s", DB_NAME);
Properties connProps = new Properties();

// Configure connection properties
// Configure Postgres driver properties
connProps.setProperty("user", DB_USER);
connProps.setProperty("password", "password");
connProps.setProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory");

// Include Cloud SQL connection properties
// Configure Cloud SQL connector properties
connProps.setProperty("cloudSqlInstance", CONNECTION_NAME);
connProps.setProperty("enableIamAuth", "true");

// Instruct the JDBC connection to use the named connector instead of the default.
// Configure the named connector registered as "my-connector"
connProps.setProperty("cloudSqlNamedConnector", "my-connector");

// Initialize connection pool
Expand Down

0 comments on commit ef9adf1

Please sign in to comment.