Search in sources :

Example 6 with MergeEnvironmentConfig

use of com.thoughtworks.go.config.merge.MergeEnvironmentConfig in project gocd by gocd.

the class PatchEnvironmentCommandTest method shouldNotAllowRemovingRemoteEnvironmentVariables.

@Test
public void shouldNotAllowRemovingRemoteEnvironmentVariables() throws Exception {
    String variableName = "remote-env-var-to-remove";
    BasicEnvironmentConfig local = new BasicEnvironmentConfig(environmentName);
    local.setOrigins(new FileConfigOrigin());
    BasicEnvironmentConfig remote = new BasicEnvironmentConfig(environmentName);
    remote.addEnvironmentVariable(variableName, "bar");
    ConfigRepoConfig configRepo = new ConfigRepoConfig(new GitMaterialConfig("foo/bar.git", "master"), "myPlugin");
    remote.setOrigins(new RepoConfigOrigin(configRepo, "latest"));
    MergeEnvironmentConfig mergedConfig = new MergeEnvironmentConfig(local, remote);
    envVarsToRemove.add(variableName);
    PatchEnvironmentCommand command = new PatchEnvironmentCommand(goConfigService, environmentConfig, pipelinesToAdd, pipelinesToRemove, agentsToAdd, agentsToRemove, envVarsToAdd, envVarsToRemove, currentUser, actionFailed, result);
    assertFalse(cruiseConfig.getEnvironments().find(environmentName).getVariables().hasVariable(variableName));
    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 = "Environment variable with name 'remote-env-var-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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) FileConfigOrigin(com.thoughtworks.go.config.remote.FileConfigOrigin) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) Test(org.junit.Test)

Example 7 with MergeEnvironmentConfig

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) FileConfigOrigin(com.thoughtworks.go.config.remote.FileConfigOrigin) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) Test(org.junit.Test)

Example 8 with MergeEnvironmentConfig

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));
}
Also used : FileConfigOrigin(com.thoughtworks.go.config.remote.FileConfigOrigin) BasicEnvironmentConfig(com.thoughtworks.go.config.BasicEnvironmentConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 9 with MergeEnvironmentConfig

use of com.thoughtworks.go.config.merge.MergeEnvironmentConfig in project gocd by gocd.

the class CruiseConfigTestBase method shouldModifyEmptyEnvironmentConfigWithUIOrigin.

@Test
public void shouldModifyEmptyEnvironmentConfigWithUIOrigin() {
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    PartialConfig partialConfig = PartialConfigMother.withEnvironment("remoteEnv");
    partialConfig.setOrigins(new RepoConfigOrigin());
    cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, true, partialConfig);
    cruiseConfig.getEnvironments().get(0).addAgent("agent");
    MergeEnvironmentConfig mergedEnv = (MergeEnvironmentConfig) cruiseConfig.getEnvironments().get(0);
    assertThat(mergedEnv.getFirstEditablePart().getAgents(), hasItem(new EnvironmentAgentConfig("agent")));
}
Also used : MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) Test(org.junit.Test)

Example 10 with MergeEnvironmentConfig

use of com.thoughtworks.go.config.merge.MergeEnvironmentConfig in project gocd by gocd.

the class CruiseConfigTestBase method shouldCreateEmptyEnvironmentConfigForEditsWithUIOrigin_WhenFileHasNoEnvironmentAnd2RemoteParts_AndForEdit.

@Test
public void shouldCreateEmptyEnvironmentConfigForEditsWithUIOrigin_WhenFileHasNoEnvironmentAnd2RemoteParts_AndForEdit() {
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    PartialConfig partialConfig1 = PartialConfigMother.withEnvironment("remoteEnv");
    partialConfig1.setOrigins(new RepoConfigOrigin());
    PartialConfig partialConfig2 = PartialConfigMother.withEnvironment("remoteEnv");
    partialConfig2.setOrigins(new RepoConfigOrigin());
    cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, true, partialConfig1, partialConfig2);
    assertThat(cruiseConfig.getEnvironments().size(), is(1));
    assertThat(cruiseConfig.getEnvironments().get(0) instanceof MergeEnvironmentConfig, is(true));
    assertThat(cruiseConfig.getEnvironments().get(0).name(), is(new CaseInsensitiveString("remoteEnv")));
    MergeEnvironmentConfig mergedEnv = (MergeEnvironmentConfig) cruiseConfig.getEnvironments().get(0);
    assertThat(mergedEnv.size(), is(3));
}
Also used : MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) Test(org.junit.Test)

Aggregations

MergeEnvironmentConfig (com.thoughtworks.go.config.merge.MergeEnvironmentConfig)14 Test (org.junit.Test)12 FileConfigOrigin (com.thoughtworks.go.config.remote.FileConfigOrigin)4 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)4 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)3 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)3 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 Cloner (com.rits.cloning.Cloner)2 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 BasicEnvironmentConfig (com.thoughtworks.go.config.BasicEnvironmentConfig)1 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1