Skip to content

Commit ef0d358

Browse files
committed
test(logging): centralize test prefix handling inside RemoteLoggingHelper
Embeds TEST_SINK_PREFIX directly within RemoteLoggingHelper.formatForTest(), ensuring all client test cases across the entire test suite consistently receive standardized prefix formatting without requiring class-local wrappers or repetitive literal string prefixes. BUG=b/482174880 TAG=agy CONV=d4a74f94-579a-4c3f-96c3-f90fcbc6c699
1 parent fd9b20e commit ef0d358

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

java-logging/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/RemoteLoggingHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public class RemoteLoggingHelper {
3838

3939
private static final Logger log = Logger.getLogger(RemoteLoggingHelper.class.getName());
40+
private static final String TEST_SINK_PREFIX = "test-";
4041
private final LoggingOptions options;
4142

4243
private RemoteLoggingHelper(LoggingOptions options) {
@@ -96,7 +97,8 @@ public static RemoteLoggingHelper create() {
9697
* name.
9798
*/
9899
public static String formatForTest(String name) {
99-
return name + "-" + UUID.randomUUID();
100+
String prefix = name.startsWith(TEST_SINK_PREFIX) ? "" : TEST_SINK_PREFIX;
101+
return prefix + name + "-" + UUID.randomUUID();
100102
}
101103

102104
private static RetrySettings retrySettings() {

java-logging/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITSinkTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.logging.it;
1818

19+
import static com.google.cloud.logging.testing.RemoteLoggingHelper.formatForTest;
1920
import static org.junit.Assert.assertEquals;
2021
import static org.junit.Assert.assertFalse;
2122
import static org.junit.Assert.assertNotNull;
@@ -29,7 +30,6 @@
2930
import com.google.cloud.logging.LoggingException;
3031
import com.google.cloud.logging.Sink;
3132
import com.google.cloud.logging.SinkInfo;
32-
import com.google.cloud.logging.testing.RemoteLoggingHelper;
3333
import com.google.common.collect.Sets;
3434
import java.util.Iterator;
3535
import java.util.Set;
@@ -40,10 +40,6 @@ public class ITSinkTest extends BaseSystemTest {
4040

4141
private static final String TEST_SINK_PREFIX = "test-";
4242

43-
private static String formatForTest(String name) {
44-
return RemoteLoggingHelper.formatForTest(TEST_SINK_PREFIX + name);
45-
}
46-
4743
@BeforeClass
4844
public static void setUp() {
4945
// Cleanup all stucked sinks if any

0 commit comments

Comments
 (0)