Skip to content

Commit 6e60ed6

Browse files
committed
Fix tests
1 parent 92d1ecf commit 6e60ed6

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

dd-java-agent/agent-profiling/profiling-controller/src/test/java/com/datadog/profiling/controller/TempLocationManagerTest.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ void testDefault() throws Exception {
2424
assertTrue(Files.isReadable(tempDir));
2525
assertTrue(Files.isExecutable(tempDir));
2626
assertTrue(tempDir.endsWith("pid_" + PidHelper.getPid()));
27-
28-
// fake temp location
29-
Path fakeTempDir = tempDir.getParent().resolve("pid_00000");
30-
Files.createDirectories(fakeTempDir);
31-
tempLocationManager.cleanup(false);
32-
// fake temp location should be deleted
33-
// real temp location should be kept
34-
assertFalse(Files.exists(fakeTempDir));
35-
assertTrue(Files.exists(tempDir));
3627
}
3728

3829
@Test
@@ -69,4 +60,25 @@ void testFromConfigNotWritable() throws Exception {
6960
TempLocationManager tempLocationManager = new TempLocationManager(configProvider);
7061
assertThrows(IllegalStateException.class, tempLocationManager::getTempDir);
7162
}
63+
64+
@Test
65+
void testCleanup() throws Exception {
66+
Path myDir = Paths.get(System.getProperty("java.io.tmpdir"), "test4");
67+
Files.createDirectories(myDir);
68+
Properties props = new Properties();
69+
props.put(ProfilingConfig.PROFILING_TEMP_DIR, myDir.toString());
70+
ConfigProvider configProvider = ConfigProvider.withPropertiesOverride(props);
71+
TempLocationManager tempLocationManager = new TempLocationManager(configProvider);
72+
Path tempDir = tempLocationManager.getTempDir();
73+
assertNotNull(tempDir);
74+
75+
// fake temp location
76+
Path fakeTempDir = tempDir.getParent().resolve("pid_00000");
77+
Files.createDirectories(fakeTempDir);
78+
tempLocationManager.cleanup(false);
79+
// fake temp location should be deleted
80+
// real temp location should be kept
81+
assertFalse(Files.exists(fakeTempDir));
82+
assertTrue(Files.exists(tempDir));
83+
}
7284
}

0 commit comments

Comments
 (0)