From 24fa4ca6c2628367b3d028ef80560df6f657ecfd Mon Sep 17 00:00:00 2001 From: Ben Grabham Date: Tue, 18 Oct 2016 13:57:38 +0100 Subject: [PATCH] Add string version of circleAwareLogDirectory. This solves the case when multiple classes have the same name, or the rule is part of a superclass --- .../com/palantir/docker/compose/logging/LogDirectory.java | 6 +++++- .../palantir/docker/compose/logging/LogDirectoryTest.java | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/palantir/docker/compose/logging/LogDirectory.java b/src/main/java/com/palantir/docker/compose/logging/LogDirectory.java index 7187fc101..471e3d561 100644 --- a/src/main/java/com/palantir/docker/compose/logging/LogDirectory.java +++ b/src/main/java/com/palantir/docker/compose/logging/LogDirectory.java @@ -21,8 +21,12 @@ private LogDirectory() {} * @param testClass the JUnit test class whose name will appear on the log folder */ public static String circleAwareLogDirectory(Class testClass) { + return circleAwareLogDirectory(testClass.getSimpleName()); + } + + public static String circleAwareLogDirectory(String logDirectoryName) { String artifactRoot = Optional.ofNullable(System.getenv("CIRCLE_ARTIFACTS")).orElse("build"); - return artifactRoot + "/dockerLogs/" + testClass.getSimpleName(); + return artifactRoot + "/dockerLogs/" + logDirectoryName; } /** diff --git a/src/test/java/com/palantir/docker/compose/logging/LogDirectoryTest.java b/src/test/java/com/palantir/docker/compose/logging/LogDirectoryTest.java index 34969ce98..4db0cfe55 100644 --- a/src/test/java/com/palantir/docker/compose/logging/LogDirectoryTest.java +++ b/src/test/java/com/palantir/docker/compose/logging/LogDirectoryTest.java @@ -37,5 +37,13 @@ public void circleAwareLogDirectory_should_use_circle_environment_variable_if_av assertThat(directory, is("/tmp/circle-artifacts.g4DjuuD/dockerLogs/SomeTestClass")); } + @Test + public void circleAwareLogDirectory_should_append_logDirectoryName_to_path() { + variablesRule.set("CIRCLE_ARTIFACTS", "/tmp/circle-artifacts.123456"); + + String directory = LogDirectory.circleAwareLogDirectory("some-path"); + assertThat(directory, is("/tmp/circle-artifacts.123456/dockerLogs/some-path")); + } + private static class SomeTestClass {} }