@Test
public void testWithNonExistingPath() throws IOException, InterruptedException {
String path = "not/existing";
TestWrapper wrapper = new TestWrapper(standardSecrets(path));
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream logger = new PrintStream(baos);
SimpleBuildWrapper.Context context = null;
Run<?, ?> build = mock(Build.class);
when(build.getParent()).thenReturn(null);
EnvVars envVars = mock(EnvVars.class);
when(envVars.expand(path)).thenReturn(path);
wrapper.run(context, build, envVars, logger);
try { // now we expect the exception to raise
wrapper.vaultConfig.setFailIfNotFound(true);
wrapper.run(context, build, envVars, logger);
} catch (VaultPluginException e) {
assertThat(e.getMessage(), is("Vault credentials not found for 'not/existing'"));
}
wrapper.verifyCalls();
assertThat(new String(baos.toByteArray(), StandardCharsets.UTF_8),
containsString("Vault credentials not found for 'not/existing'"));
}
private <T extends Describable<T>,D extends Descriptor<T>> void populateMetaSteps(List<Descriptor<?>> r, Class<T> c) {
Jenkins j = Jenkins.getInstance();
for (Descriptor<?> d : j.getDescriptorList(c)) {
if (SimpleBuildStep.class.isAssignableFrom(d.clazz) && symbolForObject(d) != null) {
r.add(d);
} else if (SimpleBuildWrapper.class.isAssignableFrom(d.clazz) && symbolForObject(d) != null) {
r.add(d);
}
}
}
/**
* Indicates this step wraps a block of other steps
*/
@Exported
public boolean getIsBlockContainer() {
return SimpleBuildWrapper.class.isAssignableFrom(model.getType());
}