Skip to content

Fixing some failing RTDB tests - #334

Merged
hiranya911 merged 3 commits into
masterfrom
hkj-test-fix
Dec 12, 2019
Merged

Fixing some failing RTDB tests#334
hiranya911 merged 3 commits into
masterfrom
hkj-test-fix

Conversation

@hiranya911

Copy link
Copy Markdown
Contributor

Following test failures are observed when running on environments not set up for ADC:

testDbUrlIsEmulatorUrlForDbRefWithPath(com.google.firebase.database.FirebaseDatabaseTest)  Time elapsed: 0.13 sec  <<< ERROR!
java.lang.IllegalStateException: java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
	at com.google.firebase.database.FirebaseDatabaseTest.testDbUrlIsEmulatorUrlForDbRefWithPath(FirebaseDatabaseTest.java:252)
Caused by: java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
	at com.google.firebase.database.FirebaseDatabaseTest.testDbUrlIsEmulatorUrlForDbRefWithPath(FirebaseDatabaseTest.java:252)

testDbUrlIsEmulatorUrlWhenSettingOptionsManually(com.google.firebase.database.FirebaseDatabaseTest)  Time elapsed: 0.001 sec  <<< ERROR!
java.lang.IllegalStateException: java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
	at com.google.firebase.database.FirebaseDatabaseTest.testDbUrlIsEmulatorUrlWhenSettingOptionsManually(FirebaseDatabaseTest.java:215)
Caused by: java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
	at com.google.firebase.database.FirebaseDatabaseTest.testDbUrlIsEmulatorUrlWhenSettingOptionsManually(FirebaseDatabaseTest.java:215)

This PR fixes these issues by using explicit credentials.

@micahstairs

Copy link
Copy Markdown
Contributor

Thanks! I've tested this on my machine (which was failing before) and this seems to work now.

GoogleCredentials credentials = GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream());
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(credentials)
.build();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor nit: We can put this in a helper method and re-use across tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Refactored the options into a static constant.

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.

3 participants