Пример #1
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);
  }
Пример #2
0
 public PartialConfig toPartialConfig(CRParseResult crPartialConfig) {
   PartialConfig partialConfig = new PartialConfig();
   for (CREnvironment crEnvironment : crPartialConfig.getEnvironments()) {
     EnvironmentConfig environment = toEnvironmentConfig(crEnvironment);
     partialConfig.getEnvironments().add(environment);
   }
   Map<String, List<CRPipeline>> pipesByGroup =
       groupPipelinesByGroupName(crPartialConfig.getPipelines());
   for (Map.Entry<String, List<CRPipeline>> crPipelineGroup : pipesByGroup.entrySet()) {
     BasicPipelineConfigs pipelineConfigs = toBasicPipelineConfigs(crPipelineGroup);
     partialConfig.getGroups().add(pipelineConfigs);
   }
   return partialConfig;
 }
Пример #3
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));
  }
Пример #4
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"));
  }
Пример #5
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));
  }
Пример #6
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."));
  }
Пример #7
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"));
  }
Пример #8
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."));
 }
Пример #9
0
  @Test
  public void
      shouldGenerateAMapOfAllPipelinesAndTheirParentDependencies_WhenThereAreRemotePipelinesInMap() {
    /*
     *    -----+ p2 --> p4
     *  p1
     *    -----+ p3 --> remote-pipe-1
     *
     * */
    PipelineConfig p1 = createPipelineConfig("p1", "s1", "j1");
    PipelineConfig p2 = createPipelineConfig("p2", "s2", "j1");
    p2.addMaterialConfig(
        new DependencyMaterialConfig(
            new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1")));
    PipelineConfig p3 = createPipelineConfig("p3", "s3", "j1");
    p3.addMaterialConfig(
        new DependencyMaterialConfig(
            new CaseInsensitiveString("p1"), new CaseInsensitiveString("s1")));
    PipelineConfig p4 = createPipelineConfig("p4", "s4", "j1");
    p4.addMaterialConfig(
        new DependencyMaterialConfig(
            new CaseInsensitiveString("p2"), new CaseInsensitiveString("s2")));
    pipelines.addAll(Arrays.asList(p4, p2, p1, p3));

    PipelineConfig remotePipe1 = createPipelineConfig("remote-pipe-1", "s5", "j1");
    remotePipe1.addMaterialConfig(
        new DependencyMaterialConfig(
            new CaseInsensitiveString("p3"), new CaseInsensitiveString("s3")));
    PartialConfig part = new PartialConfig();
    part.getGroups().addPipeline("remoteGroup", remotePipe1);
    cruiseConfig = new BasicCruiseConfig(new BasicCruiseConfig(pipelines), part);
    Map<String, List<PipelineConfig>> expectedPipelines =
        cruiseConfig.generatePipelineVsDownstreamMap();
    assertThat(expectedPipelines.size(), is(5));
    assertThat(expectedPipelines.get("p1"), hasItems(p2, p3));
    assertThat(expectedPipelines.get("p2"), hasItems(p4));
    assertThat(expectedPipelines.get("p3"), hasItems(remotePipe1));
    assertThat(expectedPipelines.get("remote-pipe-1").isEmpty(), is(true));
    assertThat(expectedPipelines.get("p4").isEmpty(), is(true));
  }
Пример #10
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."));
  }