Skip to content

Commit

Permalink
Allow LoggingAppender default options test to pass locally and on GCE
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 committed Sep 11, 2018
1 parent 709099f commit 90e28af
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ Logging getLogging() {
@Before
public void setUp() {}

private final WriteOption[] defaultWriteOptions =
new WriteOption[] {
WriteOption.logName("java.log"),
WriteOption.resource(
MonitoredResource.newBuilder("global")
.setLabels(
new ImmutableMap.Builder<String, String>().put("project_id", projectId).build())
.build())
};
private final WriteOption defaultWriteOptionLogName = WriteOption.logName("java.log");
// For local test runs, the default option is global
private final WriteOption defaultWriteOptionResourceGlobal = WriteOption.resource(
MonitoredResource.newBuilder("global")
.setLabels(
new ImmutableMap.Builder<String, String>().put("project_id", projectId).build())
.build());
// CI runs on GCE so the default is gce_instance
private final WriteOption defaultWriteOptionResourceGCE = WriteOption.resource(
MonitoredResource.newBuilder("gce_instance")
.setLabels(
new ImmutableMap.Builder<String, String>().put("project_id", projectId).build())
.build());

@Test
public void testFlushLevelConfigUpdatesLoggingFlushSeverity() {
Expand Down Expand Up @@ -179,8 +183,8 @@ public void testDefaultWriteOptionsHasExpectedDefaults() {
LoggingEvent loggingEvent = createLoggingEvent(Level.ERROR, timestamp.getSeconds());
loggingAppender.doAppend(loggingEvent);

assertThat(logNameArg.getValue()).isEqualTo(defaultWriteOptions[0]);
assertThat(resourceArg.getValue()).isEqualTo(defaultWriteOptions[1]);
assertThat(logNameArg.getValue()).isEqualTo(defaultWriteOptionLogName);
assertThat(resourceArg.getValue()).isAnyOf(defaultWriteOptionResourceGlobal, defaultWriteOptionResourceGCE);
}

private LoggingEvent createLoggingEvent(Level level, long timestamp) {
Expand Down

0 comments on commit 90e28af

Please sign in to comment.