Skip to content

Commit 5642713

Browse files
peter-afrigisgithub-actions[bot]
authored andcommitted
Fix loadFromEmptyReadOnlyDirectoryFails test
which fails when building gwc-release (Docker) on Windows
1 parent ef6d142 commit 5642713

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationTest.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -578,18 +578,35 @@ public void loadFromReadOnlyDirectory() throws GeoWebCacheException {
578578
}
579579
}
580580

581-
@Test
582-
public void loadFromEmptyReadOnlyDirectoryFails() throws GeoWebCacheException, IOException {
583-
File roEmptyDir = this.temp.newFolder();
584-
Assume.assumeTrue(
585-
"Ignore if setWritable(false) does not succeed, may happen on Windows", roEmptyDir.setWritable(false));
586-
try {
587-
config = new XMLConfiguration(null, roEmptyDir.getAbsolutePath());
588-
config.setGridSetBroker(gridSetBroker);
589-
590-
assertThrows(ConfigurationException.class, () -> config.afterPropertiesSet());
591-
} finally {
592-
roEmptyDir.setWritable(true);
593-
}
594-
}
581+
@Test
582+
public void loadFromEmptyReadOnlyDirectoryFails() throws GeoWebCacheException, IOException {
583+
File roEmptyDir = this.temp.newFolder();
584+
585+
// Try to make it read-only
586+
roEmptyDir.setWritable(false);
587+
588+
// Actively probe whether the directory is still writable (for gwc-release Docker on Windows)
589+
File probe = new File(roEmptyDir, "probe");
590+
boolean canWrite;
591+
try {
592+
canWrite = probe.createNewFile();
593+
if (canWrite) {
594+
probe.delete();
595+
}
596+
} catch (IOException e) {
597+
canWrite = false;
598+
}
599+
600+
// Skip if we can still write, this may happen on Windows
601+
Assume.assumeTrue("Skipping: directory is still writable", !canWrite);
602+
603+
try {
604+
config = new XMLConfiguration(null, roEmptyDir.getAbsolutePath());
605+
config.setGridSetBroker(gridSetBroker);
606+
607+
assertThrows(ConfigurationException.class, () -> config.afterPropertiesSet());
608+
} finally {
609+
roEmptyDir.setWritable(true);
610+
}
611+
}
595612
}

0 commit comments

Comments
 (0)