Search in sources :

Example 31 with EnvironmentVariableContext

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();
}
Also used : AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) File(java.io.File) Before(org.junit.Before)

Example 32 with 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));
    }
}
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 33 with EnvironmentVariableContext

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'"));
}
Also used : RunIfConfigs(com.thoughtworks.go.domain.RunIfConfigs) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) File(java.io.File) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 34 with EnvironmentVariableContext

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()));
    }
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) ArgumentCaptor(org.mockito.ArgumentCaptor) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) CruiseControlException(com.thoughtworks.go.util.command.CruiseControlException) Test(org.junit.Test)

Example 35 with EnvironmentVariableContext

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);
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Before(org.junit.Before)

Aggregations

EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)94 Test (org.junit.Test)74 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)19 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)16 File (java.io.File)14 Date (java.util.Date)13 Modification (com.thoughtworks.go.domain.materials.Modification)12 Modifications (com.thoughtworks.go.domain.materials.Modifications)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)9 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)9 Before (org.junit.Before)8 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)7 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)6 Materials (com.thoughtworks.go.config.materials.Materials)6 Builder (com.thoughtworks.go.domain.builder.Builder)6 HashMap (java.util.HashMap)6 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)5 RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)5 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)5 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)5