Merge pull request #26677 from izeye

* pr/26677:
  Test optional directories without sub-directories
  Fix "Allow optional directories without sub-directories"

Closes gh-26677
pull/26691/head
Phillip Webb 4 years ago
commit 35f1194651

@ -267,7 +267,7 @@ public class StandardConfigDataLocationResolver
private Set<StandardConfigDataResource> resolvePatternEmptyDirectories(StandardConfigDataReference reference) {
Resource[] subdirectories = this.resourceLoader.getResources(reference.getDirectory(), ResourceType.DIRECTORY);
ConfigDataLocation location = reference.getConfigDataLocation();
if (location.isOptional() && ObjectUtils.isEmpty(subdirectories)) {
if (!location.isOptional() && ObjectUtils.isEmpty(subdirectories)) {
String message = String.format("Config data location '%s' contains no subdirectories", location);
throw new ConfigDataLocationNotFoundException(location, message, null);
}

@ -715,7 +715,14 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
void runWhenMandatoryWildcardLocationHasNoSubdirectories() {
assertThatExceptionOfType(ConfigDataLocationNotFoundException.class).isThrownBy(
() -> this.application.run("--spring.config.location=file:src/test/resources/config/0-empty/*/"))
.withMessage("Config data location 'file:src/test/resources/config/0-empty/*/' cannot be found");
.withMessage(
"Config data location 'file:src/test/resources/config/0-empty/*/' contains no subdirectories");
}
@Test
void runWhenOptionalWildcardLocationHasNoSubdirectories() {
assertThatNoException().isThrownBy(() -> this.application
.run("--spring.config.location=optional:file:src/test/resources/config/0-empty/*/"));
}
@Test

Loading…
Cancel
Save