Exemple #1
0
  @Test
  public void shouldReturnTheCorrectLocalizedMessageForDuplicatePipelinesInAnEnvironment() {
    BasicEnvironmentConfig environmentConfig = environmentConfig("uat");
    goConfigService.addPipeline(
        PipelineConfigMother.createPipelineConfig("foo", "dev", "job"), "foo-grp");
    environmentConfig.addPipeline(new CaseInsensitiveString("foo"));
    goConfigService.addEnvironment(environmentConfig);

    ArrayList<String> pipelines = new ArrayList<>();
    pipelines.add("foo");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    service.createEnvironment(
        env("foo-env", pipelines, new ArrayList<Map<String, String>>(), new ArrayList<String>()),
        new Username(new CaseInsensitiveString("any")),
        result);

    result = new HttpLocalizedOperationResult();
    service.createEnvironment(
        env("env", pipelines, new ArrayList<Map<String, String>>(), new ArrayList<String>()),
        new Username(new CaseInsensitiveString("any")),
        result);
    assertThat(
        result.message(localizer),
        is(
            "Failed to add environment. Associating pipeline(s) which is already part of uat environment"));
  }
Exemple #2
0
 @Test
 public void shouldUpdateExistingEnvironment() throws Exception {
   BasicEnvironmentConfig uat = environmentConfig("uat");
   goConfigService.addPipeline(
       PipelineConfigMother.createPipelineConfig("foo", "dev", "job"), "foo-grp");
   goConfigService.addPipeline(
       PipelineConfigMother.createPipelineConfig("bar", "dev", "job"), "foo-grp");
   Username user = Username.ANONYMOUS;
   agentConfigService.addAgent(new AgentConfig("uuid-1", "host-1", "192.168.1.2"), user);
   agentConfigService.addAgent(new AgentConfig("uuid-2", "host-2", "192.168.1.3"), user);
   uat.addPipeline(new CaseInsensitiveString("foo"));
   uat.addAgent("uuid-2");
   uat.addEnvironmentVariable("env-one", "ONE");
   uat.addEnvironmentVariable("env-two", "TWO");
   goConfigService.addEnvironment(new BasicEnvironmentConfig(new CaseInsensitiveString("dev")));
   goConfigService.addEnvironment(new BasicEnvironmentConfig(new CaseInsensitiveString("qa")));
   goConfigService.addEnvironment(uat);
   goConfigService.addEnvironment(
       new BasicEnvironmentConfig(new CaseInsensitiveString("acceptance")));
   goConfigService.addEnvironment(
       new BasicEnvironmentConfig(new CaseInsensitiveString("function_testing")));
   EnvironmentConfig newUat = new BasicEnvironmentConfig(new CaseInsensitiveString("prod"));
   newUat.addPipeline(new CaseInsensitiveString("bar"));
   newUat.addAgent("uuid-1");
   newUat.addEnvironmentVariable("env-three", "THREE");
   HttpLocalizedOperationResult result =
       service.updateEnvironment(
           "uat",
           newUat,
           new Username(new CaseInsensitiveString("foo")),
           goConfigDao.md5OfConfigFile());
   EnvironmentConfig updatedEnv = service.named("prod");
   assertThat(updatedEnv.name(), is(new CaseInsensitiveString("prod")));
   assertThat(updatedEnv.getAgents().getUuids(), is(Arrays.asList("uuid-1")));
   assertThat(updatedEnv.getPipelineNames(), is(Arrays.asList(new CaseInsensitiveString("bar"))));
   EnvironmentVariablesConfig updatedVariables = new EnvironmentVariablesConfig();
   updatedVariables.add("env-three", "THREE");
   assertThat(updatedEnv.getVariables(), is(updatedVariables));
   EnvironmentsConfig currentEnvironments = goConfigService.getCurrentConfig().getEnvironments();
   assertThat(currentEnvironments.indexOf(updatedEnv), is(2));
   assertThat(currentEnvironments.size(), is(5));
 }
Exemple #3
0
  @Test
  public void shouldDeleteAnEnvironment() throws Exception {
    String environmentName = "dev";
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    goConfigService.addEnvironment(
        new BasicEnvironmentConfig(new CaseInsensitiveString(environmentName)));

    assertTrue(goConfigService.hasEnvironmentNamed(new CaseInsensitiveString(environmentName)));
    service.deleteEnvironment(
        service.getEnvironmentConfig(environmentName),
        new Username(new CaseInsensitiveString("foo")),
        result);
    assertFalse(goConfigService.hasEnvironmentNamed(new CaseInsensitiveString(environmentName)));
    assertThat(
        result.message(localizer), containsString("Environment 'dev' was deleted successfully."));
  }