use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PluggableSCMMaterialTest method shouldNotThrowUpWhenAdditionalDataIsRandomJunkAndNotJSON.
@Test
public void shouldNotThrowUpWhenAdditionalDataIsRandomJunkAndNotJSON() {
ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1");
SCM scmConfig = SCMMother.create("scm-id", "tw-dev", "pluginid", "version", new Configuration(k1));
PluggableSCMMaterial material = new PluggableSCMMaterial();
material.setSCMConfig(scmConfig);
material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
Modifications modifications = new Modifications(new Modification("loser", "comment", "email", new Date(), "revision-123", "salkdfjdsa-jjgkj!!!vcxknbvkjk"));
EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_K1"), is("v1"));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PluggableSCMMaterialTest method shouldNotThrowUpWhenAdditionalDataIsNull.
@Test
public void shouldNotThrowUpWhenAdditionalDataIsNull() {
ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1");
SCM scmConfig = SCMMother.create("scm-id", "tw-dev", "pluginid", "version", new Configuration(k1));
PluggableSCMMaterial material = new PluggableSCMMaterial();
material.setSCMConfig(scmConfig);
material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
Modifications modifications = new Modifications(new Modification("loser", "comment", "email", new Date(), "revision-123", null));
EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_K1"), is("v1"));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldBuildExecutorConfigPlusExecutionContextAndInvokeTheTaskExecutorWithIt.
@Test
public void shouldBuildExecutorConfigPlusExecutionContextAndInvokeTheTaskExecutorWithIt() throws Exception {
Task task = mock(Task.class);
TaskConfig defaultTaskConfig = mock(TaskConfig.class);
when(task.config()).thenReturn(defaultTaskConfig);
final TaskConfig executorTaskConfig = mock(TaskConfig.class);
final TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class);
PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, pluggableTask, TEST_PLUGIN_ID, "test-directory") {
@Override
protected TaskConfig buildTaskConfig(TaskConfig config) {
return executorTaskConfig;
}
@Override
protected TaskExecutionContext buildTaskContext(DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext, String consoleLogCharset) {
return taskExecutionContext;
}
};
TaskExecutor taskExecutor = mock(TaskExecutor.class);
when(taskExecutor.execute(executorTaskConfig, taskExecutionContext)).thenReturn(new ExecutionResult());
when(task.executor()).thenReturn(taskExecutor);
taskBuilder.executeTask(task, null, null, "utf-8");
verify(task).config();
verify(task).executor();
verify(taskExecutor).execute(executorTaskConfig, taskExecutionContext);
assertThat(ReflectionUtil.getStaticField(JobConsoleLogger.class, "context"), is(not(nullValue())));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldPublishErrorMessageIfPluginReturnsAFailureResponse.
@Test
public void shouldPublishErrorMessageIfPluginReturnsAFailureResponse() 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) {
return ExecutionResult.failure("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());
assertThat(captor.getValue(), is("err"));
assertThat(e.getMessage(), is("err"));
}
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class SvnRemoteRepository method start.
public void start() throws Exception {
if (processWrapper != null) {
throw new RuntimeException("Cannot start repository twice!");
}
port = RandomPort.find(toString());
CommandLine svnserve = CommandLine.createCommandLine("svnserve").withArgs("-d", "--foreground", "--listen-port", Integer.toString(port), "-r", repo.projectRepositoryRoot().getCanonicalPath()).withEncoding("utf-8");
consumer = inMemoryConsumer();
processWrapper = svnserve.execute(consumer, new EnvironmentVariableContext(), null);
RandomPort.waitForPort(port);
if (!processWrapper.isRunning()) {
throw new RuntimeException("Could not run command " + svnserve);
}
}
Aggregations