public static PipelineTemplateConfig createTemplateWithParams(String templateName, String... paramNameAndValue) { PipelineTemplateConfig template = createTemplate(templateName); for (String nameAndValue : paramNameAndValue) { template.get(0).getJobs().get(0).addVariable(String.format("name-%s", nameAndValue), String.format("value-#{%s}", nameAndValue)); } return template; } }
@Test public void shouldErrorOutWhenTryingToAddTwoStagesWithSameName() { BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); PipelineTemplateConfig pipelineTemplateConfig = new PipelineTemplateConfig(new CaseInsensitiveString("template"), StageConfigMother.manualStage("stage1"), StageConfigMother.manualStage("stage1")); pipelineTemplateConfig.validate(ConfigSaveValidationContext.forChain(cruiseConfig)); assertThat(pipelineTemplateConfig.get(0).errors().isEmpty(), is(false)); assertThat(pipelineTemplateConfig.get(1).errors().isEmpty(), is(false)); assertThat(pipelineTemplateConfig.get(0).errors().on(StageConfig.NAME), is("You have defined multiple stages called 'stage1'. Stage names are case-insensitive and must be unique.")); assertThat(pipelineTemplateConfig.get(1).errors().on(StageConfig.NAME), is("You have defined multiple stages called 'stage1'. Stage names are case-insensitive and must be unique.")); }
@Test public void shouldLoadConfigWithPipelineTemplate() throws Exception { String content = configWithTemplates( "<templates>" + " <pipeline name='erbshe'>" + " <stage name='stage1'>" + " <jobs>" + " <job name='job1' />" + " </jobs>" + " </stage>" + " </pipeline>" + "</templates>"); TemplatesConfig templates = ConfigMigrator.loadWithMigration(content).config.getTemplates(); assertThat(templates.size(), is(1)); assertThat(templates.get(0).size(), is(1)); assertThat(templates.get(0).get(0), is(StageConfigMother.custom("stage1", "job1"))); }
@Test public void validate_withinTemplates_shouldPopulateErrorOnSrcFileOrSrcDirOrDestIfIsNotAValidFilePathPattern() { String dest = ".."; String src = ".."; PipelineTemplateConfig template = PipelineTemplateConfigMother.createTemplate("template-1"); StageConfig stage = template.get(0); JobConfig job = stage.getJobs().get(0); FetchTask task = new FetchTask(template.name(), stage.name(), job.name(), src, dest); ValidationContext context = ConfigSaveValidationContext.forChain(config, template, stage, job); task.validate(context); assertThat(task.errors().isEmpty(), is(false)); String messageForSrc = String.format("Task of job '%s' in stage '%s' of template '%s' has src path '%s' which is outside the working directory.", job.name(), stage.name(), template.name(), src); assertThat(task.errors().on(FetchTask.SRC), is(messageForSrc)); String messageForDest = String.format("Task of job '%s' in stage '%s' of template '%s' has dest path '%s' which is outside the working directory.", job.name(), stage.name(), template.name(), dest); assertThat(task.errors().on(FetchTask.DEST), is(messageForDest)); }