use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigValidationTest method shouldFailValidationIfAJobIsDeletedWhileItsStillReferredToByADescendentPipelineThroughFetchArtifact.
@Test
public void shouldFailValidationIfAJobIsDeletedWhileItsStillReferredToByADescendentPipelineThroughFetchArtifact() {
BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("p1", "p2", "p3");
PipelineConfig p1 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p1"));
PipelineConfig p2 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p2"));
PipelineConfig p3 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p3"));
p2.addMaterialConfig(new DependencyMaterialConfig(p1.name(), p1.first().name()));
JobConfig p2S2J2 = new JobConfig(new CaseInsensitiveString("j2"));
p2S2J2.addTask(fetchTaskFromSamePipeline(p2));
p2.add(new StageConfig(new CaseInsensitiveString("stage2"), new JobConfigs(p2S2J2)));
p3.addMaterialConfig(new DependencyMaterialConfig(p2.name(), p2.first().name()));
p3.first().getJobs().first().addTask(new FetchTask(new CaseInsensitiveString("p1/p2"), p1.first().name(), p1.first().getJobs().first().name(), "src", "dest"));
StageConfig stageConfig = new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig(new CaseInsensitiveString("new-job"))));
PipelineConfig pipelineConfig = new PipelineConfig(p1.name(), new MaterialConfigs(), stageConfig);
String group = cruiseConfig.getGroups().first().getGroup();
cruiseConfig.update(group, pipelineConfig.name().toString(), pipelineConfig);
PipelineConfigSaveValidationContext validationContext = PipelineConfigSaveValidationContext.forChain(false, group, cruiseConfig, pipelineConfig);
pipelineConfig.validateTree(validationContext);
assertThat(pipelineConfig.errors().on("base"), is("\"p3 :: stage :: job\" tries to fetch artifact from job \"p1 :: stage :: job\" which does not exist."));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigValidationTest method shouldFailValidationIfAStageIsDeletedWhileItsStillReferredToByADownstreamPipeline.
@Test
public void shouldFailValidationIfAStageIsDeletedWhileItsStillReferredToByADownstreamPipeline() {
BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("p1", "p2");
PipelineConfig p1 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p1"));
PipelineConfig p2 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p2"));
p2.addMaterialConfig(new DependencyMaterialConfig(p1.name(), p1.first().name()));
String group = cruiseConfig.getGroups().first().getGroup();
StageConfig stageConfig = new StageConfig(new CaseInsensitiveString("s1"), new JobConfigs(new JobConfig(new CaseInsensitiveString("j1"))));
PipelineConfig pipelineConfig = new PipelineConfig(p1.name(), new MaterialConfigs(), stageConfig);
cruiseConfig.update(group, pipelineConfig.name().toString(), pipelineConfig);
PipelineConfigSaveValidationContext validationContext = PipelineConfigSaveValidationContext.forChain(false, group, cruiseConfig, pipelineConfig);
pipelineConfig.validateTree(validationContext);
assertThat(pipelineConfig.errors().on("base"), is("Stage with name 'stage' does not exist on pipeline 'p1', it is being referred to from pipeline 'p2' (cruise-config.xml)"));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigValidationTest method shouldAddValidationErrorsFromStagesOntoPipelineIfPipelineIsAssociatedToATemplate.
@Test
public void shouldAddValidationErrorsFromStagesOntoPipelineIfPipelineIsAssociatedToATemplate() {
BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("p1", "p2", "p3");
PipelineConfig p1 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p1"));
PipelineConfig p2 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p2"));
PipelineConfig p3 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p3"));
p2.addMaterialConfig(new DependencyMaterialConfig(p1.name(), p1.first().name()));
p3.addMaterialConfig(new DependencyMaterialConfig(p2.name(), p2.first().name()));
p3.first().getJobs().first().addTask(new FetchTask(new CaseInsensitiveString("p1/p2"), p1.first().name(), p1.first().getJobs().first().name(), "src", "dest"));
StageConfig stageConfig = new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig(new CaseInsensitiveString("new-job"))));
PipelineConfig pipelineConfig = new PipelineConfig(p1.name(), new MaterialConfigs(), stageConfig);
String group = cruiseConfig.getGroups().first().getGroup();
cruiseConfig.update(group, pipelineConfig.name().toString(), pipelineConfig);
PipelineConfigSaveValidationContext validationContext = PipelineConfigSaveValidationContext.forChain(false, group, cruiseConfig, pipelineConfig);
pipelineConfig.validateTree(validationContext);
assertThat(pipelineConfig.errors().on("base"), is("\"p3 :: stage :: job\" tries to fetch artifact from job \"p1 :: stage :: job\" which does not exist."));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigValidationTest method shouldFailValidateWhenUpstreamPipelineForDependencyMaterailDoesNotExist.
@Test
public void shouldFailValidateWhenUpstreamPipelineForDependencyMaterailDoesNotExist() {
String upstreamPipeline = "non-existant";
PipelineConfig pipelineConfig = GoConfigMother.createPipelineConfigWithMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString(upstreamPipeline), new CaseInsensitiveString("non-existant")));
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(pipelineConfig));
boolean isValid = pipelineConfig.validateTree(PipelineConfigSaveValidationContext.forChain(true, cruiseConfig.getGroups().first().getGroup(), cruiseConfig, pipelineConfig));
assertThat(isValid, is(false));
ConfigErrors materialErrors = pipelineConfig.materialConfigs().first().errors();
assertThat(materialErrors.isEmpty(), is(false));
assertThat(materialErrors.firstError(), is("Pipeline with name 'non-existant' does not exist, it is defined as a dependency for pipeline 'pipeline' (cruise-config.xml)"));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigValidationTest method shouldAllowDependenciesFromMultiplePipelinesToTheSamePipeline.
@Test
public void shouldAllowDependenciesFromMultiplePipelinesToTheSamePipeline() throws Exception {
pipeline.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("pipeline2"), new CaseInsensitiveString("stage")));
PipelineConfig pipeline3 = config.pipelineConfigByName(new CaseInsensitiveString("pipeline3"));
pipeline3.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("pipeline2"), new CaseInsensitiveString("stage")));
pipeline.validate(validationContext);
assertThat(pipeline.errors().isEmpty(), is(true));
pipeline3.validate(validationContext);
assertThat(pipeline3.errors().isEmpty(), is(true));
}
Aggregations