use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class JobConfigTest method shouldValidateAgainstSettingRunInstanceCountToIncorrectValue.
@Test
void shouldValidateAgainstSettingRunInstanceCountToIncorrectValue() {
JobConfig jobConfig1 = new JobConfig(new CaseInsensitiveString("test"));
jobConfig1.setRunInstanceCount(-1);
jobConfig1.validate(ConfigSaveValidationContext.forChain(new BasicCruiseConfig()));
ConfigErrors configErrors1 = jobConfig1.errors();
assertThat(configErrors1.isEmpty()).isFalse();
assertThat(configErrors1.on(JobConfig.RUN_TYPE)).isEqualTo("'Run Instance Count' cannot be a negative number as it represents number of instances GoCD needs to spawn during runtime.");
JobConfig jobConfig2 = new JobConfig(new CaseInsensitiveString("test"));
ReflectionUtil.setField(jobConfig2, "runInstanceCount", "abcd");
jobConfig2.validate(ConfigSaveValidationContext.forChain(new BasicCruiseConfig()));
ConfigErrors configErrors2 = jobConfig2.errors();
assertThat(configErrors2.isEmpty()).isFalse();
assertThat(configErrors2.on(JobConfig.RUN_TYPE)).isEqualTo("'Run Instance Count' should be a valid positive integer as it represents number of instances GoCD needs to spawn during runtime.");
JobConfig jobConfig3 = new JobConfig(new CaseInsensitiveString("test"));
ReflectionUtil.setField(jobConfig3, "runInstanceCount", "0");
jobConfig3.validate(ConfigSaveValidationContext.forChain(new BasicCruiseConfig()));
ConfigErrors configErrors3 = jobConfig3.errors();
assertThat(configErrors3.isEmpty()).isFalse();
assertThat(configErrors3.on(JobConfig.RUN_TYPE)).isEqualTo("'Run Instance Count' cannot be 0 as it represents number of instances GoCD needs to spawn during runtime.");
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class BuildTaskTest method shouldErrorOutIfWorkingDirectoryIsOutsideTheCurrentWorkingDirectory.
@Test
public void shouldErrorOutIfWorkingDirectoryIsOutsideTheCurrentWorkingDirectory() {
BuildTask task = new BuildTask() {
@Override
public String getTaskType() {
return "build";
}
@Override
public String getTypeForDisplay() {
return null;
}
@Override
public String command() {
return null;
}
@Override
public String arguments() {
return null;
}
};
task.setWorkingDirectory("/blah");
CruiseConfig config = GoConfigMother.configWithPipelines("pipeline");
PipelineConfig pipeline = config.pipelineConfigByName(new CaseInsensitiveString("pipeline"));
StageConfig stage = pipeline.get(0);
JobConfig job = stage.getJobs().get(0);
job.addTask(task);
List<ConfigErrors> errors = config.validateAfterPreprocess();
assertThat(errors.size(), is(1));
String message = "Task of job 'job' in stage 'stage' of pipeline 'pipeline' has path '/blah' which is outside the working directory.";
assertThat(task.errors().on(BuildTask.WORKING_DIRECTORY), is(message));
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class DependencyMaterialConfigTest method shouldNOTBeValidIfTheReferencedPipelineDoesNotExist.
@Test
void shouldNOTBeValidIfTheReferencedPipelineDoesNotExist() throws Exception {
CruiseConfig config = GoConfigMother.configWithPipelines("pipeline1", "pipeline2", "pipeline3", "go");
DependencyMaterialConfig dependencyMaterialConfig = new DependencyMaterialConfig(new CaseInsensitiveString("pipeline-not-exist"), new CaseInsensitiveString("stage"));
dependencyMaterialConfig.validate(ConfigSaveValidationContext.forChain(config, pipelineConfig));
ConfigErrors configErrors = dependencyMaterialConfig.errors();
assertThat(configErrors.isEmpty()).isFalse();
assertThat(configErrors.on(DependencyMaterialConfig.PIPELINE_STAGE_NAME)).contains("Pipeline with name 'pipeline-not-exist' does not exist");
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class UpdateClusterProfileCommand method isValid.
@Override
public boolean isValid(CruiseConfig preprocessedConfig) {
ElasticProfiles allElasticAgentProfiles = preprocessedConfig.getElasticConfig().getProfiles();
allElasticAgentProfiles.validateTree(new ConfigSaveValidationContext(preprocessedConfig));
List<ConfigErrors> allErrors = ErrorCollector.getAllErrors(allElasticAgentProfiles);
if (!allErrors.isEmpty()) {
throw new GoConfigInvalidException(preprocessedConfig, allErrors.get(0).firstError());
}
return isValidForCreateOrUpdate(preprocessedConfig);
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class CreatePipelineConfigCommandTest method createPipelineConfigShouldValidateAllExternalArtifacts.
@Test
public void createPipelineConfigShouldValidateAllExternalArtifacts() {
PluggableArtifactConfig s3 = mock(PluggableArtifactConfig.class);
PluggableArtifactConfig docker = mock(PluggableArtifactConfig.class);
when(goConfigService.artifactStores()).thenReturn(mock(ArtifactStores.class));
when(goConfigService.findGroupNameByPipeline(new CaseInsensitiveString("P1"))).thenReturn("group");
ConfigErrors configErrors = new ConfigErrors();
when(s3.errors()).thenReturn(configErrors);
when(docker.errors()).thenReturn(configErrors);
JobConfig job1 = JobConfigMother.jobWithNoResourceRequirement();
JobConfig job2 = JobConfigMother.jobWithNoResourceRequirement();
job1.artifactTypeConfigs().add(s3);
job2.artifactTypeConfigs().add(docker);
PipelineConfig pipeline = PipelineConfigMother.pipelineConfig("P1", new StageConfig(new CaseInsensitiveString("S1"), new JobConfigs(job1)), new StageConfig(new CaseInsensitiveString("S2"), new JobConfigs(job2)));
CreatePipelineConfigCommand command = new CreatePipelineConfigCommand(goConfigService, pipeline, username, localizedOperationResult, "group", externalArtifactsService);
BasicCruiseConfig preprocessedConfig = GoConfigMother.defaultCruiseConfig();
preprocessedConfig.addPipelineWithoutValidation("group", pipeline);
command.isValid(preprocessedConfig);
verify(externalArtifactsService).validateExternalArtifactConfig(eq(s3), any(), eq(true));
verify(externalArtifactsService).validateExternalArtifactConfig(eq(docker), any(), eq(true));
}
Aggregations