use of com.thoughtworks.go.config.merge.MergeEnvironmentConfig 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.config.merge.MergeEnvironmentConfig 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"));
}
use of com.thoughtworks.go.config.merge.MergeEnvironmentConfig in project gocd by gocd.
the class PatchEnvironmentCommandTest method shouldNotAllowRemovingRemoteAgents.
@Test
public void shouldNotAllowRemovingRemoteAgents() throws Exception {
String agentUUID = "remote-agent-to-remove";
BasicEnvironmentConfig local = new BasicEnvironmentConfig(environmentName);
local.setOrigins(new FileConfigOrigin());
BasicEnvironmentConfig remote = new BasicEnvironmentConfig(environmentName);
remote.addAgent(agentUUID);
ConfigRepoConfig configRepo = new ConfigRepoConfig(new GitMaterialConfig("foo/bar.git", "master"), "myPlugin");
remote.setOrigins(new RepoConfigOrigin(configRepo, "latest"));
MergeEnvironmentConfig mergedConfig = new MergeEnvironmentConfig(local, remote);
agentsToRemove.add(agentUUID);
PatchEnvironmentCommand command = new PatchEnvironmentCommand(goConfigService, environmentConfig, pipelinesToAdd, pipelinesToRemove, agentsToAdd, agentsToRemove, envVarsToAdd, envVarsToRemove, currentUser, actionFailed, result);
assertFalse(cruiseConfig.getEnvironments().find(environmentName).containsPipeline(new CaseInsensitiveString(agentUUID)));
command.update(cruiseConfig);
// preprocess
cruiseConfig.getEnvironments().replace(cruiseConfig.getEnvironments().find(environmentName), mergedConfig);
boolean isValid = command.isValid(cruiseConfig);
assertFalse(isValid);
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
String message = "Agent with uuid 'remote-agent-to-remove' cannot be removed from environment 'Dev' as the association has been defined remotely in [foo/bar.git at latest]";
expectedResult.unprocessableEntity(actionFailed.addParam(message));
assertThat(result, is(expectedResult));
}
use of com.thoughtworks.go.config.merge.MergeEnvironmentConfig in project gocd by gocd.
the class EnvironmentsConfigTest method shouldGetLocalPartsWhenOriginIsMixed.
@Test
public void shouldGetLocalPartsWhenOriginIsMixed() {
env.setOrigins(new FileConfigOrigin());
BasicEnvironmentConfig prodLocalPart = new BasicEnvironmentConfig(new CaseInsensitiveString("PROD"));
prodLocalPart.addAgent("1235");
prodLocalPart.setOrigins(new FileConfigOrigin());
BasicEnvironmentConfig prodRemotePart = new BasicEnvironmentConfig(new CaseInsensitiveString("PROD"));
prodRemotePart.setOrigins(new RepoConfigOrigin());
MergeEnvironmentConfig pairEnvironmentConfig = new MergeEnvironmentConfig(prodLocalPart, prodRemotePart);
configs.add(pairEnvironmentConfig);
assertThat(configs.getLocal().size(), is(2));
assertThat(configs.getLocal(), hasItem(env));
assertThat(configs.getLocal(), hasItem(prodLocalPart));
}
use of com.thoughtworks.go.config.merge.MergeEnvironmentConfig in project gocd by gocd.
the class EnvironmentConfigServiceTest method shouldReturnAllTheLocalEnvironments.
@Test
void shouldReturnAllTheLocalEnvironments() {
String uat = "uat";
BasicEnvironmentConfig local = new BasicEnvironmentConfig(new CaseInsensitiveString("uat"));
local.addEnvironmentVariable("user", "admin");
BasicEnvironmentConfig remote = new BasicEnvironmentConfig(new CaseInsensitiveString("uat"));
remote.addEnvironmentVariable("foo", "bar");
MergeEnvironmentConfig merged = new MergeEnvironmentConfig(local, remote);
EnvironmentsConfig environments = new EnvironmentsConfig();
environments.add(merged);
when(agentService.getAgentInstances()).thenReturn(new AgentInstances(null));
environmentConfigService.syncEnvironments(environments);
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
BasicEnvironmentConfig env = (BasicEnvironmentConfig) environmentConfigService.getEnvironmentConfig(uat).getLocal();
cruiseConfig.addEnvironment(env);
List<BasicEnvironmentConfig> expectedToEdit = singletonList(GoConfigMother.deepClone(env));
when(mockGoConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
assertThat(environmentConfigService.getAllLocalEnvironments(), is(expectedToEdit));
}
Aggregations