use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class EnvironmentVariableTest method addToIfExists_shouldNotAddEnvironmentVariableToEnvironmentVariableContextWhenVariableIDoesNotExistInContext.
@Test
public void addToIfExists_shouldNotAddEnvironmentVariableToEnvironmentVariableContextWhenVariableIDoesNotExistInContext() {
final EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
final EnvironmentVariable environmentVariable = new EnvironmentVariable("foo", "bar");
when(environmentVariableContext.hasProperty("foo")).thenReturn(false);
environmentVariable.addToIfExists(environmentVariableContext);
verify(environmentVariableContext, times(0)).setProperty("foo", "bar", false);
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class EnvironmentVariablesTest method addTo_shouldAddEnvironmentVariablesToEnvironmentVariableContext.
@Test
public void addTo_shouldAddEnvironmentVariablesToEnvironmentVariableContext() {
final EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
final EnvironmentVariables environmentVariables = new EnvironmentVariables(new EnvironmentVariable("foo", "bar"), new EnvironmentVariable("baz", "car", true));
environmentVariables.addTo(environmentVariableContext);
verify(environmentVariableContext, times(1)).setProperty("foo", "bar", false);
verify(environmentVariableContext, times(1)).setProperty("baz", "car", true);
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PluggableSCMMaterial method populateEnvironmentContext.
@Override
public void populateEnvironmentContext(EnvironmentVariableContext context, MaterialRevision materialRevision, File workingDir) {
context.setProperty(getEnvironmentVariableKey("GO_SCM_%s_%s", "LABEL"), materialRevision.getRevision().getRevision(), false);
for (ConfigurationProperty configurationProperty : scmConfig.getConfiguration()) {
context.setProperty(getEnvironmentVariableKey("GO_SCM_%s_%s", configurationProperty.getConfigurationKey().getName()), configurationProperty.getValue(), configurationProperty.isSecure());
}
HashMap<String, String> additionalData = materialRevision.getLatestModification().getAdditionalDataMap();
if (additionalData != null) {
for (Map.Entry<String, String> entry : additionalData.entrySet()) {
boolean isSecure = false;
for (EnvironmentVariableContext.EnvironmentVariable secureEnvironmentVariable : context.getSecureEnvironmentVariables()) {
String urlEncodedValue = null;
try {
urlEncodedValue = URLEncoder.encode(secureEnvironmentVariable.value(), "UTF-8");
} catch (UnsupportedEncodingException e) {
}
boolean isSecureEnvironmentVariableEncoded = !StringUtils.isBlank(urlEncodedValue) && !secureEnvironmentVariable.value().equals(urlEncodedValue);
if (isSecureEnvironmentVariableEncoded && entry.getValue().contains(urlEncodedValue)) {
isSecure = true;
break;
}
}
String key = entry.getKey();
String value = entry.getValue();
context.setProperty(getEnvironmentVariableKey("GO_SCM_%s_%s", key), value, isSecure);
}
}
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class EnvironmentConfigServiceTest method shouldListAllEnvironmentVariablesDefinedForAConfigRepoEnvironment.
@Test
public void shouldListAllEnvironmentVariablesDefinedForAConfigRepoEnvironment() throws Exception {
EnvironmentsConfig environmentConfigs = new EnvironmentsConfig();
BasicEnvironmentConfig localPart = environment("uat");
localPart.addEnvironmentVariable("Var1", "Value1");
localPart.addEnvironmentVariable("Var2", "Value2");
BasicEnvironmentConfig remotePart = remote("uat");
remotePart.addEnvironmentVariable("remote-var1", "remote-value-1");
environmentConfigs.add(new MergeEnvironmentConfig(localPart, remotePart));
environmentConfigService.sync(environmentConfigs);
EnvironmentVariableContext environmentVariableContext = environmentConfigService.environmentVariableContextFor("uat-pipeline");
assertThat(environmentVariableContext.getProperties().size(), is(4));
assertThat(environmentVariableContext.getProperty("GO_ENVIRONMENT_NAME"), is("uat"));
assertThat(environmentVariableContext.getProperty("Var1"), is("Value1"));
assertThat(environmentVariableContext.getProperty("Var2"), is("Value2"));
assertThat(environmentVariableContext.getProperty("remote-var1"), is("remote-value-1"));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class EnvironmentConfigServiceTest method shouldListAllEnvironmentVariablesDefinedForRemoteOnlyEnvironment.
@Test
public void shouldListAllEnvironmentVariablesDefinedForRemoteOnlyEnvironment() throws Exception {
EnvironmentsConfig environmentConfigs = new EnvironmentsConfig();
BasicEnvironmentConfig remotePart = remote("uat");
remotePart.addEnvironmentVariable("remote-var1", "remote-value-1");
environmentConfigs.add(new MergeEnvironmentConfig(remotePart));
environmentConfigService.sync(environmentConfigs);
EnvironmentVariableContext environmentVariableContext = environmentConfigService.environmentVariableContextFor("uat-pipeline");
assertThat(environmentVariableContext.getProperties().size(), is(2));
assertThat(environmentVariableContext.getProperty("GO_ENVIRONMENT_NAME"), is("uat"));
assertThat(environmentVariableContext.getProperty("remote-var1"), is("remote-value-1"));
}
Aggregations