Skip to content

Commit

Permalink
Make getRdsClient protected for testing; mock getRdsClient to avoid t…
Browse files Browse the repository at this point in the history
…est failures on unauthenticated runners
  • Loading branch information
malessi committed Nov 26, 2024
1 parent 27a034e commit 03e9c1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gov.cms.bfd.sharedutils.database;

import com.google.common.annotations.VisibleForTesting;
import gov.cms.bfd.sharedutils.config.AwsClientConfig;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.services.rds.RdsClient;
Expand Down Expand Up @@ -82,7 +83,8 @@ public HostListProviderSupplier getHostListProvider() {
* @param awsClientConfig the AWS client configuration to use for the {@link RdsClient}
* @return the RDS client
*/
private RdsClient getRdsClient(AwsClientConfig awsClientConfig) {
@VisibleForTesting
protected RdsClient getRdsClient(AwsClientConfig awsClientConfig) {
final var rdsClientBuilder = RdsClient.builder();
awsClientConfig.configureAwsService(rdsClientBuilder);
rdsClientBuilder.credentialsProvider(DefaultCredentialsProvider.create());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package gov.cms.bfd.sharedutils.database;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;

import gov.cms.bfd.sharedutils.config.AwsClientConfig;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.jdbc.HostListProviderService;
import software.amazon.jdbc.PluginService;
import software.amazon.jdbc.dialect.HostListProviderSupplier;
Expand All @@ -26,7 +30,8 @@ void testGetHostListProviderReturnsCorrectHostListSupplierWhenCalled() {
final var mockPluginService = mock(PluginService.class);
final var mockAwsClientConfig = mock(AwsClientConfig.class);
final var properties = new Properties();
final var dialect = new StateAwareAuroraPgDialect(mockAwsClientConfig);
final var dialect = spy(new StateAwareAuroraPgDialect(mockAwsClientConfig));
doReturn(mock(RdsClient.class)).when(dialect).getRdsClient(any(AwsClientConfig.class));
final var supplier = dialect.getHostListProvider();

// Act
Expand Down

0 comments on commit 03e9c1e

Please sign in to comment.