Search in sources :

Example 1 with MergeEnvironmentConfig

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

Example 2 with MergeEnvironmentConfig

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

Example 3 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 4 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 5 with MergeEnvironmentConfig

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));
}
Also used : AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) Test(org.junit.jupiter.api.Test)

Aggregations

MergeEnvironmentConfig (com.thoughtworks.go.config.merge.MergeEnvironmentConfig)16 Test (org.junit.jupiter.api.Test)10 FileConfigOrigin (com.thoughtworks.go.config.remote.FileConfigOrigin)4 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)4 Test (org.junit.Test)4 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)3 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 EnvironmentConfig (com.thoughtworks.go.config.EnvironmentConfig)2 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)2 BasicEnvironmentConfig (com.thoughtworks.go.config.BasicEnvironmentConfig)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)1 DisplayName (org.junit.jupiter.api.DisplayName)1