Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix behavior in unitialized environment
Browse files Browse the repository at this point in the history
unit tests run without actual credentials or GCP environment is configured.
need to mock discovery of environment properties such as default project id.
minherz committed Jan 18, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9b17e9d commit 56d6891
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -224,7 +224,14 @@ private static LogRecord newLogRecord(Level level, String message) {

@Test
public void testDefaultHandlerCreation() {
replay(options, logging);
// mocks behavior of MonitoredResourceUtil which is used by LoggingOptions.getDefaultInstance()
// static method
ResourceTypeEnvironmentGetter getterMock =
EasyMock.createMock(ResourceTypeEnvironmentGetter.class);
expect(getterMock.getAttribute("project/project-id")).andReturn(PROJECT);
expect(getterMock.getAttribute("")).andStubReturn(null);
MonitoredResourceUtil.setEnvironmentGetter(getterMock);
replay(options, logging, getterMock);
assertNotNull(new LoggingHandler());
}

0 comments on commit 56d6891

Please sign in to comment.