@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)); }
@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())); }
@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(); }
@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); }
@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)); }
@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"))); }
@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)); }
@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)); }
@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)); }
@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")); }
@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.")); }
@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")); }
@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.")); }
@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)); }
@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.")); }