Add code to replace '/' with '(_)' in labels (#999)

This commit is contained in:
Dana P'Simer
2018-05-08 07:25:48 -04:00
committed by Ryan Baxter
parent 0fd0c7b801
commit 53da694260
2 changed files with 23 additions and 0 deletions

View File

@@ -176,6 +176,9 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
Object[] args = new String[] { name, profile };
if (StringUtils.hasText(label)) {
if (label.contains("/")) {
label = label.replace("/", "(_)");
}
args = new String[] { name, profile, label };
path = path + "/{label}";
}

View File

@@ -67,6 +67,17 @@ public class ConfigServicePropertySourceLocatorTests {
assertNotNull(this.locator.locate(this.environment));
}
@Test
public void sunnyDayWithLabelThatContainsASlash() {
Environment body = new Environment("app", "master");
mockRequestResponseWithLabel(
new ResponseEntity<>(body, HttpStatus.OK), "release(_)v1.0.0");
this.locator.setRestTemplate(this.restTemplate);
EnvironmentTestUtils.addEnvironment(this.environment,
"spring.cloud.config.label:release/v1.0.0");
assertNotNull(this.locator.locate(this.environment));
}
@Test
public void sunnyDayWithNoSuchLabel() {
mockRequestResponseWithLabel(new ResponseEntity<Void>((Void) null,
@@ -235,4 +246,13 @@ public class ConfigServicePropertySourceLocatorTests {
Mockito.any(Class.class), Matchers.anyString(),
Matchers.anyString())).thenReturn(response);
}
@SuppressWarnings("unchecked")
private void mockRequestResponseWithoutLabelWithExpectedName(ResponseEntity<?> response, String expectedName) {
Mockito.when(
this.restTemplate.exchange(Mockito.any(String.class),
Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class),
Mockito.any(Class.class), Matchers.eq(expectedName),
Matchers.anyString())).thenReturn(response);
}
}