Skip to content

Commit

Permalink
test(codegen): set top-level mock credentials for language-starter mo…
Browse files Browse the repository at this point in the history
…dule unit tests (#1443)

This PR patches unit tests added in #1355 to all have mock top-level credentials configured.
  • Loading branch information
emmileaf authored Jan 11, 2023
1 parent 049d7fc commit eabdc52
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class LanguageAutoConfigurationTests {
new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(
GcpContextAutoConfiguration.class, LanguageServiceSpringAutoConfiguration.class));
GcpContextAutoConfiguration.class, LanguageServiceSpringAutoConfiguration.class))
.withPropertyValues(
"spring.cloud.gcp.credentials.location=file:" + TOP_LEVEL_CREDENTIAL_LOCATION);

@Test
void testLanguageServiceClientCreated() {
Expand All @@ -76,7 +78,6 @@ void testLanguageServiceClientCreated() {
void testCredentials_fromServicePropertiesIfSpecified() {
this.contextRunner
.withPropertyValues(
"spring.cloud.gcp.credentials.location=file:" + TOP_LEVEL_CREDENTIAL_LOCATION,
"com.google.cloud.language.v1.language-service.credentials.location=file:"
+ SERVICE_CREDENTIAL_LOCATION)
.run(
Expand All @@ -91,17 +92,13 @@ void testCredentials_fromServicePropertiesIfSpecified() {

@Test
void testCredentials_fromTopLevelIfNoServiceProperties() {
this.contextRunner
.withPropertyValues(
"spring.cloud.gcp.credentials.location=file:" + TOP_LEVEL_CREDENTIAL_LOCATION)
.run(
ctx -> {
LanguageServiceClient client = ctx.getBean(LanguageServiceClient.class);
Credentials credentials =
client.getSettings().getCredentialsProvider().getCredentials();
assertThat(((ServiceAccountCredentials) credentials).getClientId())
.isEqualTo(TOP_LEVEL_CREDENTIAL_CLIENT_ID);
});
this.contextRunner.run(
ctx -> {
LanguageServiceClient client = ctx.getBean(LanguageServiceClient.class);
Credentials credentials = client.getSettings().getCredentialsProvider().getCredentials();
assertThat(((ServiceAccountCredentials) credentials).getClientId())
.isEqualTo(TOP_LEVEL_CREDENTIAL_CLIENT_ID);
});
}

@Test
Expand Down

0 comments on commit eabdc52

Please sign in to comment.