use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class BuildWorkTest method shouldNotRunTaskWhichConditionDoesNotMatch.
@Test
public void shouldNotRunTaskWhichConditionDoesNotMatch() throws Exception {
buildWork = (BuildWork) getWork(WILL_NOT_RUN, PIPELINE_NAME);
buildWork.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, buildRepository, artifactManipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, pluginRequestProcessorRegistry));
String actual = artifactManipulator.consoleOut();
assertThat(actual, not(containsString("run when status is failed")));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class BuildWorkTest method shouldSendAResultStatusToServerWhenAThrowableErrorIsThrown.
@Test
public void shouldSendAResultStatusToServerWhenAThrowableErrorIsThrown() throws Exception {
BuildAssignment buildAssignment = mock(BuildAssignment.class);
when(buildAssignment.shouldFetchMaterials()).thenThrow(new AssertionError());
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(true));
assertThat(buildRepository.states.size(), is(1));
assertThat(buildRepository.states.get(0), is(JobState.Preparing));
}
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class BuildWorkTest method shouldOverrideAgentGO_SERVER_URL_EnvironmentVariableIfDefinedInJob.
@Test
public void shouldOverrideAgentGO_SERVER_URL_EnvironmentVariableIfDefinedInJob() throws Exception {
buildWork = (BuildWork) getWork(WITH_GO_SERVER_URL_ENV_VAR, PIPELINE_NAME);
buildWork.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, buildRepository, artifactManipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, pluginRequestProcessorRegistry));
String consoleOut = artifactManipulator.consoleOut();
assertThat(consoleOut, matches("'GO_SERVER_URL' (to|with) value '" + SERVER_URL));
assertThat(consoleOut, containsString("[go] overriding environment variable 'GO_SERVER_URL' with value 'go_server_url_from_job'"));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class BuildWorkTest method shouldNotBombWhenCreatingWorkingDirectoryIfCleanWorkingDirectoryFlagIsTrue.
@Test
public void shouldNotBombWhenCreatingWorkingDirectoryIfCleanWorkingDirectoryFlagIsTrue() throws Exception {
String pipelineName = "pipeline" + UUID.randomUUID();
File workingdir = new File("pipelines/" + pipelineName);
if (workingdir.exists()) {
FileUtils.deleteDirectory(workingdir);
}
assertThat(workingdir.exists(), is(false));
buildWork = (BuildWork) getWork(WILL_PASS, pipelineName, true, true);
buildWork.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, buildRepository, artifactManipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, pluginRequestProcessorRegistry));
assertThat(artifactManipulator.consoleOut(), not(containsString("Working directory \"" + workingdir.getAbsolutePath() + "\" is not a directory")));
assertThat(buildRepository.results.contains(Passed), is(true));
assertThat(workingdir.exists(), is(true));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class BuildWorkTest method shouldCleanAgentWorkingDirectoryIfExistsWhenCleanWorkingDirIsTrue.
@Test
public void shouldCleanAgentWorkingDirectoryIfExistsWhenCleanWorkingDirIsTrue() throws Exception {
String pipelineName = "pipeline" + UUID.randomUUID();
File workingdir = new File("pipelines/" + pipelineName);
if (workingdir.exists()) {
FileUtils.deleteDirectory(workingdir);
}
workingdir.mkdirs();
createDummyFilesAndDirectories(workingdir);
assertThat(workingdir.listFiles().length, is(2));
buildWork = (BuildWork) getWork(WILL_PASS, pipelineName, false, true);
buildWork.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, buildRepository, artifactManipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, pluginRequestProcessorRegistry));
assertThat(artifactManipulator.consoleOut(), containsString("Cleaning working directory \"" + workingdir.getAbsolutePath()));
assertThat(buildRepository.results.contains(Passed), is(true));
assertThat(workingdir.exists(), is(true));
assertThat(workingdir.listFiles().length, is(0));
}
Aggregations