Search in sources :

Example 71 with AgentRuntimeInfo

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")));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 72 with AgentRuntimeInfo

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));
    }
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) File(java.io.File) Test(org.junit.Test)

Example 73 with AgentRuntimeInfo

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'"));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 74 with AgentRuntimeInfo

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));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) StringContains.containsString(org.hamcrest.core.StringContains.containsString) File(java.io.File) Test(org.junit.Test)

Example 75 with AgentRuntimeInfo

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));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) StringContains.containsString(org.hamcrest.core.StringContains.containsString) File(java.io.File) Test(org.junit.Test)

Aggregations

AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)123 Test (org.junit.Test)101 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)34 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)26 File (java.io.File)16 AgentInstruction (com.thoughtworks.go.remote.AgentInstruction)13 StringContains.containsString (org.hamcrest.core.StringContains.containsString)13 FakeBuildRepositoryRemote (com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote)12 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)11 UploadEntry (com.thoughtworks.go.matchers.UploadEntry)10 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)10 ArrayList (java.util.ArrayList)10 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)9 AgentInstance (com.thoughtworks.go.domain.AgentInstance)7 Before (org.junit.Before)7 Expectations (org.jmock.Expectations)4 RunIf (com.googlecode.junit.ext.RunIf)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)3 Date (java.util.Date)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3