use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class BuildWorkArtifactFetchingTest method setUp.
@Before
public void setUp() throws IOException {
buildWorkingDirectory = new File("tmp");
PipelineConfigMother.createPipelineConfig(PIPELINE_NAME, STAGE_NAME, JOB_NAME);
agentIdentifier = new AgentIdentifier("localhost", "127.0.0.1", AGENT_UUID);
buildRepository = new com.thoughtworks.go.remote.work.BuildRepositoryRemoteStub();
environmentVariableContext = new EnvironmentVariableContext();
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class BuildWorkTest method shouldSendAResultStatusToServerWhenAnExceptionIsThrown.
@Test
public void shouldSendAResultStatusToServerWhenAnExceptionIsThrown() throws Exception {
BuildAssignment buildAssignment = mock(BuildAssignment.class);
when(buildAssignment.shouldFetchMaterials()).thenThrow(new RuntimeException());
when(buildAssignment.initialEnvironmentVariableContext()).thenReturn(new EnvironmentVariableContext());
when(buildAssignment.getWorkingDirectory()).thenReturn(new File("current"));
when(buildAssignment.getJobIdentifier()).thenReturn(JOB_IDENTIFIER);
buildWork = new BuildWork(buildAssignment, "utf-8");
try {
buildWork.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, buildRepository, artifactManipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, pluginRequestProcessorRegistry));
fail("Should have thrown an assertion error");
} catch (AssertionError e) {
assertThat(buildRepository.results.isEmpty(), is(false));
assertThat(buildRepository.results.get(0), is(JobResult.Failed));
}
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class BuilderTest method shouldReportErrorWhenCancelCommandDoesNotExist.
@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, WINDOWS })
public void shouldReportErrorWhenCancelCommandDoesNotExist() throws Exception {
StubBuilder stubBuilder = new StubBuilder();
CommandBuilder cancelBuilder = new CommandBuilder("echo2", "cancel task", new File("."), new RunIfConfigs(FAILED), stubBuilder, "");
CommandBuilder builder = new CommandBuilder("echo", "normal task", new File("."), new RunIfConfigs(FAILED), cancelBuilder, "");
builder.cancel(goPublisher, new EnvironmentVariableContext(), null, null, "utf-8");
assertThat(goPublisher.getMessage(), containsString("Error happened while attempting to execute 'echo2 cancel task'"));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldPublishErrorMessageIfPluginThrowsAnException.
@Test
public void shouldPublishErrorMessageIfPluginThrowsAnException() throws CruiseControlException {
PluggableTask task = mock(PluggableTask.class);
when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, pluggableTask, TEST_PLUGIN_ID, "test-directory") {
@Override
protected ExecutionResult executeTask(Task task, DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext, String consoleLogCharset) {
throw new RuntimeException("err");
}
};
try {
taskBuilder.build(goPublisher, variableContext, taskExtension, null, null, "utf-8");
fail("expected exception to be thrown");
} catch (Exception e) {
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(goPublisher).taggedConsumeLine(eq(DefaultGoPublisher.ERR), captor.capture());
String error = "Error: err";
assertThat(captor.getValue(), is(error));
assertThat(e.getMessage(), is(new RuntimeException("err").toString()));
}
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PluggableTaskEnvVarsTest method setUp.
@Before
public void setUp() throws Exception {
context = new EnvironmentVariableContext();
for (int i = 0; i < keys.size(); i++) {
context.setProperty(keys.get(i), values.get(i), i % 2 != 0);
}
envVars = new PluggableTaskEnvVars(context);
}
Aggregations