Validate items to run are valid.

fixes gh-40
This commit is contained in:
Spencer Gibb
2016-10-04 19:37:58 -06:00
parent 2d924f9359
commit c9ffd381ea
2 changed files with 21 additions and 1 deletions

View File

@@ -215,6 +215,21 @@ public class DeployerThread extends Thread {
DeployerProperties properties = context.getBean(DeployerProperties.class);
ArrayList<String> invalid = new ArrayList<>();
// validate that items in deploy, are valid deployables
for (String toDeploy : properties.getDeploy()) {
if (!properties.getDeployables().containsKey(toDeploy)) {
invalid.add(toDeploy);
}
}
if (!invalid.isEmpty()) {
logger.error("Error starting 'spring cloud'."+"\n\nThe following are not valid: '" +
collectionToCommaDelimitedString(invalid) + "'. Please check the name(s) and try again.\n" +
"Valid choices are: "+ collectionToCommaDelimitedString(properties.getDeployables().keySet())+".\n");
return;
}
ArrayList<Deployable> deployables = new ArrayList<>(
properties.getDeployables().values());
OrderComparator.sort(deployables);

View File

@@ -36,10 +36,15 @@ public class DeployerThreadTests {
assertThat(output.toString(), containsString("configserver"));
}
@Test
public void testNonOptionArgsPassedDown() throws Exception {
new DeployerThread(DeployerThread.class.getClassLoader(), "--launcher.list=true", "--spring.profiles.active=test").run();
assertThat(output.toString(), containsString("foo"));
}
@Test
public void testInvalidDeployableFails() throws Exception {
new DeployerThread(DeployerThread.class.getClassLoader(), "--launcher.deploy=foo,bar").run();
assertThat(output.toString(), containsString("The following are not valid: 'foo,bar'"));
}
}