Skip to content

Commit 90e28af

Browse files
committed
Allow LoggingAppender default options test to pass locally and on GCE
1 parent 709099f commit 90e28af

File tree

1 file changed

+15
-11
lines changed
  • google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/src/test/java/com/google/cloud/logging/logback

1 file changed

+15
-11
lines changed

google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/src/test/java/com/google/cloud/logging/logback/LoggingAppenderTest.java

+15-11
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@ Logging getLogging() {
6262
@Before
6363
public void setUp() {}
6464

65-
private final WriteOption[] defaultWriteOptions =
66-
new WriteOption[] {
67-
WriteOption.logName("java.log"),
68-
WriteOption.resource(
69-
MonitoredResource.newBuilder("global")
70-
.setLabels(
71-
new ImmutableMap.Builder<String, String>().put("project_id", projectId).build())
72-
.build())
73-
};
65+
private final WriteOption defaultWriteOptionLogName = WriteOption.logName("java.log");
66+
// For local test runs, the default option is global
67+
private final WriteOption defaultWriteOptionResourceGlobal = WriteOption.resource(
68+
MonitoredResource.newBuilder("global")
69+
.setLabels(
70+
new ImmutableMap.Builder<String, String>().put("project_id", projectId).build())
71+
.build());
72+
// CI runs on GCE so the default is gce_instance
73+
private final WriteOption defaultWriteOptionResourceGCE = WriteOption.resource(
74+
MonitoredResource.newBuilder("gce_instance")
75+
.setLabels(
76+
new ImmutableMap.Builder<String, String>().put("project_id", projectId).build())
77+
.build());
7478

7579
@Test
7680
public void testFlushLevelConfigUpdatesLoggingFlushSeverity() {
@@ -179,8 +183,8 @@ public void testDefaultWriteOptionsHasExpectedDefaults() {
179183
LoggingEvent loggingEvent = createLoggingEvent(Level.ERROR, timestamp.getSeconds());
180184
loggingAppender.doAppend(loggingEvent);
181185

182-
assertThat(logNameArg.getValue()).isEqualTo(defaultWriteOptions[0]);
183-
assertThat(resourceArg.getValue()).isEqualTo(defaultWriteOptions[1]);
186+
assertThat(logNameArg.getValue()).isEqualTo(defaultWriteOptionLogName);
187+
assertThat(resourceArg.getValue()).isAnyOf(defaultWriteOptionResourceGlobal, defaultWriteOptionResourceGCE);
184188
}
185189

186190
private LoggingEvent createLoggingEvent(Level level, long timestamp) {

0 commit comments

Comments
 (0)