示例#1
0
 @Test
 public void shouldReturnGroupsOtherThanMain_WhenMerged() {
   BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
   cruiseConfig =
       new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2"));
   assertNotSame(mainCruiseConfig.getGroups(), cruiseConfig.getGroups());
 }
示例#2
0
  @Test
  public void shouldFailToAddDuplicatePipelineAlreadyDefinedInConfigRepo() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig localCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            localCruiseConfig, PartialConfigMother.withPipelineInGroup("pipe2", "remote_group"));

    PipelineConfig pipe2Dup = PipelineConfigMother.pipelineConfig("pipe2");
    try {
      cruiseConfig.addPipeline("doesNotMatterWhichGroup", pipe2Dup);
    } catch (Exception ex) {
      assertThat(
          ex.getMessage(),
          is(
              "Pipeline called 'pipe2' is already defined in configuration repository http://some.git at 1234fed"));
    }

    assertThat(cruiseConfig.allPipelines().size(), is(2));
    assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe2")), is(true));

    assertThat(localCruiseConfig.allPipelines().size(), is(1));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe1")), is(true));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe2")), is(false));
  }
示例#3
0
 @Override
 protected BasicCruiseConfig createCruiseConfig(BasicPipelineConfigs pipelineConfigs) {
   return new BasicCruiseConfig(
       new BasicCruiseConfig(pipelineConfigs),
       // we append one more, remote pipeline in the same group as requested local ones to make
       // test use MergePipelineConfigs
       PartialConfigMother.withPipelineInGroup("remote-pipe-1", pipelineConfigs.getGroup()));
 }
示例#4
0
 @Before
 public void setup() throws Exception {
   pipelines = new BasicPipelineConfigs("existing_group", new Authorization());
   cruiseConfig =
       new BasicCruiseConfig(
           new BasicCruiseConfig(pipelines),
           PartialConfigMother.withPipelineInGroup("remote-pipe-1", "remote_group"));
   goConfigMother = new GoConfigMother();
 }
示例#5
0
  @Test
  public void shouldCollectAllTheErrorsInTheChildren_InMergedConfig() {
    BasicCruiseConfig mainCruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
    PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipe2", "g2");
    partialConfig.getGroups().get(0).get(0).setOrigin(new RepoConfigOrigin());
    CruiseConfig config = new BasicCruiseConfig(mainCruiseConfig, partialConfig);

    shouldCollectAllTheErrorsInTheChilderHelper(config);
  }
示例#6
0
  @Test
  public void shouldgetAllPipelineNamesFromAllParts() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            mainCruiseConfig,
            PartialConfigMother.withPipelineInGroup("pipe2", "g2"),
            PartialConfigMother.withPipelineInGroup("pipe3", "g3"));

    assertThat(
        cruiseConfig.getAllPipelineNames(),
        contains(
            new CaseInsensitiveString("pipe1"),
            new CaseInsensitiveString("pipe2"),
            new CaseInsensitiveString("pipe3")));
  }
示例#7
0
  @Test
  public void createsMergePipelineConfigsOnlyWhenManyParts() {
    assertThat(cruiseConfig.getGroups().get(0) instanceof MergePipelineConfigs, is(false));

    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            mainCruiseConfig, PartialConfigMother.withPipelineInGroup("pipe2", "existing_group"));
    assertThat(cruiseConfig.getGroups().get(0) instanceof MergePipelineConfigs, is(true));
  }
示例#8
0
  @Test
  public void shouldReturnFalseWhenHasNotPipelinesFrom2Parts() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2"));

    assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(false));
  }
示例#9
0
 @Test
 public void shouldReturnTrueForPipelineThatInFirstGroup_WhenFirstGroupIsRemote() {
   CruiseConfig config =
       new BasicCruiseConfig(
           new BasicCruiseConfig(),
           PartialConfigMother.withPipelineInGroup("remote-pipe-1", "remote_group"));
   assertThat(
       "shouldReturnTrueForPipelineThatInFirstGroup",
       config.isInFirstGroup(new CaseInsensitiveString("remote-pipe-1")),
       is(true));
 }
示例#10
0
  @Test
  public void shouldReturnGroupsFrom2Parts() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            mainCruiseConfig, PartialConfigMother.withPipelineInGroup("pipe2", "g2"));

    assertThat(cruiseConfig.hasPipelineGroup("g2"), is(true));
  }
示例#11
0
 @Test
 public void shouldReturnFalseForPipelineThatNotInFirstGroup_WhenSecondGroupIsRemote() {
   PipelineConfigs group1 = createGroup("group1", createPipelineConfig("pipeline1", "stage1"));
   CruiseConfig config =
       new BasicCruiseConfig(
           new BasicCruiseConfig(group1),
           PartialConfigMother.withPipelineInGroup("remote-pipe-1", "remote_group"));
   assertThat(
       "shouldReturnFalseForPipelineThatNotInFirstGroup",
       config.isInFirstGroup(new CaseInsensitiveString("pipeline2")),
       is(false));
 }
示例#12
0
  @Test
  public void addPipeline_shouldAddPipelineToMain() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    pipelines.setOrigin(new FileConfigOrigin());
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2"));
    cruiseConfig.addPipeline("group_main", PipelineConfigMother.pipelineConfig("pipe3"));

    assertThat(mainCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true));
    assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true));
  }
示例#13
0
  @Test
  public void shouldGetUniqueMaterialsWithoutConfigRepos() {
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    ConfigReposConfig reposConfig = new ConfigReposConfig();
    GitMaterialConfig configRepo = new GitMaterialConfig("http://git");
    reposConfig.add(new ConfigRepoConfig(configRepo, "myplug"));
    mainCruiseConfig.setConfigRepos(reposConfig);

    PartialConfig partialConfig = PartialConfigMother.withPipeline("pipe2");
    MaterialConfig pipeRepo = partialConfig.getGroups().get(0).get(0).materialConfigs().get(0);

    cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, partialConfig);

    Set<MaterialConfig> materials = cruiseConfig.getAllUniqueMaterialsBelongingToAutoPipelines();
    assertThat(materials, hasItem(pipeRepo));
    assertThat(materials.size(), is(1));
  }
示例#14
0
  @Test
  public void shouldCollectOriginErrorsFromEnvironments_InMergedConfig() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipe2", "g2");
    partialConfig.getGroups().get(0).get(0).setOrigin(new RepoConfigOrigin());
    cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
    BasicEnvironmentConfig uat = new BasicEnvironmentConfig(new CaseInsensitiveString("UAT"));
    uat.addPipeline(new CaseInsensitiveString("pipe2"));
    cruiseConfig.addEnvironment(uat);

    List<ConfigErrors> allErrors = cruiseConfig.validateAfterPreprocess();
    assertThat(allErrors.size(), is(1));
    assertNotNull(allErrors.get(0).on("origin"));
  }
示例#15
0
 @Test
 public void addPipeline_shouldFailToAddPipelineToMainWhenItExistsInPartialConfig() {
   pipelines =
       new BasicPipelineConfigs(
           "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
   pipelines.setOrigin(new FileConfigOrigin());
   BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
   cruiseConfig =
       new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2"));
   try {
     cruiseConfig.addPipeline("group_main", PipelineConfigMother.pipelineConfig("pipe2"));
     fail("should have thrown when trying to add pipe2 when it already exists in partial config");
   } catch (Exception ex) {
     assertThat(
         ex.getMessage(),
         containsString("Pipeline called 'pipe2' is already defined in configuration repository"));
   }
 }
示例#16
0
  @Test
  public void shouldCollectOriginErrorsFromMaterialConfigs_InMergedConfig() {
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipe2", "g2");
    partialConfig.getGroups().get(0).get(0).setOrigin(new RepoConfigOrigin());
    cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
    PipelineConfig pipeline1 =
        goConfigMother.addPipeline(cruiseConfig, "pipeline1", "stage", "build");
    PipelineConfig pipeline2 =
        PipelineConfigMother.createPipelineConfigWithStage("pipeline2", "stage");
    pipeline2.setOrigin(new RepoConfigOrigin());
    partialConfig.getGroups().addPipeline("g2", pipeline2);

    goConfigMother.setDependencyOn(cruiseConfig, pipeline1, "pipeline2", "stage");

    List<ConfigErrors> allErrors = cruiseConfig.validateAfterPreprocess();
    assertThat(allErrors.size(), is(1));
    assertNotNull(allErrors.get(0).on("origin"));
  }
示例#17
0
  @Test
  public void shouldReturnOriginAsASumOfAllOrigins() {
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    FileConfigOrigin fileOrigin = new FileConfigOrigin();
    mainCruiseConfig.setOrigins(fileOrigin);

    PartialConfig part = PartialConfigMother.withPipeline("pipe2");
    RepoConfigOrigin repoOrigin = new RepoConfigOrigin();
    part.setOrigin(repoOrigin);
    cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, part);

    ConfigOrigin allOrigins = cruiseConfig.getOrigin();
    assertThat(allOrigins instanceof MergeConfigOrigin, is(true));

    MergeConfigOrigin mergeConfigOrigin = (MergeConfigOrigin) allOrigins;
    assertThat(mergeConfigOrigin.size(), is(2));
    assertThat(mergeConfigOrigin.contains(fileOrigin), is(true));
    assertThat(mergeConfigOrigin.contains(repoOrigin), is(true));
  }
示例#18
0
  @Test
  public void
      shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenPipelinesIn2Groups() {
    BasicCruiseConfig mainCruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
    PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipeline-1", "g2");
    partialConfig.setOrigin(new RepoConfigOrigin());
    CruiseConfig config = new BasicCruiseConfig(mainCruiseConfig, partialConfig);

    List<ConfigErrors> allErrors = config.validateAfterPreprocess();
    assertThat(allErrors.size(), is(2));
    assertThat(
        allErrors.get(0).on("name"),
        is(
            "You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique."));
    assertThat(
        allErrors.get(1).on("name"),
        is(
            "You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique."));
  }
示例#19
0
 @Test
 public void
     shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig2_WhenPipelinesInDefaultGroup() {
   BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("pipeline1");
   // pipeline1 is in xml and in config repo - this is an error at merged scope
   PartialConfig remotePart = PartialConfigMother.withPipelineInGroup("pipeline1", "defaultGroup");
   remotePart.setOrigin(new RepoConfigOrigin());
   BasicCruiseConfig merged = new BasicCruiseConfig((BasicCruiseConfig) cruiseConfig, remotePart);
   List<ConfigErrors> allErrors = merged.validateAfterPreprocess();
   assertThat(remotePart.getGroups().get(0).getPipelines().get(0).errors().size(), is(1));
   assertThat(allErrors.size(), is(2));
   assertThat(
       allErrors.get(0).on("name"),
       is(
           "You have defined multiple pipelines named 'pipeline1'. Pipeline names must be unique."));
   assertThat(
       allErrors.get(1).on("name"),
       is(
           "You have defined multiple pipelines named 'pipeline1'. Pipeline names must be unique."));
 }
示例#20
0
  @Test
  public void shouldAddPipelineToExistingGroup_InMergeAndLocalScope() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig localCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            localCruiseConfig, PartialConfigMother.withPipelineInGroup("pipe2", "remote_group"));

    PipelineConfig pipe3 = PipelineConfigMother.pipelineConfig("pipe3");
    cruiseConfig.addPipeline("remote_group", pipe3);

    assertThat(cruiseConfig.allPipelines().size(), is(3));
    assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true));

    assertThat(localCruiseConfig.allPipelines().size(), is(2));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe1")), is(true));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true));
    assertThat(localCruiseConfig.pipelines("remote_group").contains(pipe3), is(true));
  }
示例#21
0
  @Test
  public void shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned() {
    // we need this case because cloning has proven to be problematic with complex object graph in
    // merged config
    BasicCruiseConfig mainCruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
    PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipeline-1", "g2");
    partialConfig.setOrigin(new RepoConfigOrigin());
    CruiseConfig config = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
    Cloner CLONER = new Cloner();
    CruiseConfig cloned = CLONER.deepClone(config);

    List<ConfigErrors> allErrors = cloned.validateAfterPreprocess();
    assertThat(allErrors.size(), is(2));
    assertThat(
        allErrors.get(0).on("name"),
        is(
            "You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique."));
    assertThat(
        allErrors.get(1).on("name"),
        is(
            "You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique."));
  }