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

fix(test): add mock method to mock credentials. #3312

Merged
merged 9 commits into from
Oct 23, 2024
Merged

fix(test): add mock method to mock credentials. #3312

merged 9 commits into from
Oct 23, 2024

Conversation

zhumin8
Copy link
Contributor

@zhumin8 zhumin8 commented Oct 18, 2024

This change is to avoid runtime error when creating the client bean #3307 (comment)
Adding a mock return for getMetricsCredentialType() because in gax we do not allow for null values (should not happen because default is set)

Also added together in this pr so ci could pass:

  • libraries bom upgrade (ci would still fail due to 1) removal of rpcs in this version 2) auth upgrade in this version that needs this fix)
  • generation workflow (to fix for 1))

BEGIN_COMMIT_OVERRIDE
fix(deps): update dependency com.google.cloud:libraries-bom to v26.49.0

fix(test): add mock method to mock credentials.
END_COMMIT_OVERRIDE

@zhumin8 zhumin8 marked this pull request as ready for review October 21, 2024 16:55
@zhumin8 zhumin8 requested a review from a team as a code owner October 21, 2024 16:55
return () -> mock(Credentials.class);
Credentials mockCredential = mock(Credentials.class);
when(mockCredential.getMetricsCredentialType())
.thenReturn(CredentialTypeForMetrics.DO_NOT_SEND);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If mock credentials were placed in core, could you avoid the duplication here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock credentials are placed under "test" folder, not accessible here.
spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/TestUtils.java
Created another util class in this module to avoid duplicating logic.

import com.google.auth.Credentials;

public class TestUtils {
public static final Credentials MOCK_CREDENTIALS = createMockCredentials();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, this is needed from classes in sub-packages within com.google.cloud.spring.autoconfigure.

Copy link

sonarcloud bot commented Oct 23, 2024

@zhumin8 zhumin8 merged commit e838c64 into main Oct 23, 2024
76 checks passed
@zhumin8 zhumin8 deleted the fix-cred-mock branch October 23, 2024 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants