aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2024-04-26 15:47:02 +0200
committerMatteo Mara <matteo.mara@sonarsource.com>2024-04-30 10:59:02 +0200
commitff98ac8245d237e3905258ab5187be1eeaf07c4e (patch)
treeb1fc72795498ec29084a569153cfd88d28b3da99
parent7a68e525099ff79027c2aee162da3d05b92fd6aa (diff)
downloadsonarqube-ff98ac8245d237e3905258ab5187be1eeaf07c4e.tar.gz
sonarqube-ff98ac8245d237e3905258ab5187be1eeaf07c4e.zip
SONAR-22159 Modify the way the creation date is set in junit test
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java11
1 files changed, 11 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
index 15ee7b69856..9d8522a897f 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
@@ -67,6 +67,7 @@ class GlobalTempFolderProviderTest {
Path tmp = workingDir.resolve(".sonartmp_" + i);
Files.createDirectories(tmp);
setFileCreationDate(tmp, creationTime);
+ assumeCorrectFileCreationDate(tmp, creationTime);
}
underTest.provide(
@@ -76,6 +77,16 @@ class GlobalTempFolderProviderTest {
assertThat(workingDir.toFile().list()).hasSize(1);
}
+ // See SONAR-22159, the test started failing due to issues in setting the correct creation time on Cirrus, skipping the test if the problem
+ // happens
+ private void assumeCorrectFileCreationDate(Path tmp, long creationTime) throws IOException {
+ FileTime fileCreationTimeSet = Files.getFileAttributeView(tmp, BasicFileAttributeView.class).readAttributes().creationTime();
+ FileTime expectedCreationTime = FileTime.fromMillis(creationTime);
+
+ assumeTrue(expectedCreationTime.compareTo(fileCreationTimeSet) >= 0,
+ String.format("Incorrect creation date set on temporary file %s: %s set instead of %s", tmp.toAbsolutePath(), fileCreationTimeSet, expectedCreationTime));
+ }
+
@Test
void createTempFolderFromSonarHome(@TempDir Path sonarUserHomePath) throws Exception {
// with sonar home, it will be in {sonar.home}/.sonartmp