Search in sources :

Example 41 with ConfigErrors

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.");
}
Also used : ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.jupiter.api.Test)

Example 42 with ConfigErrors

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));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.jupiter.api.Test)

Example 43 with ConfigErrors

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");
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.jupiter.api.Test)

Example 44 with ConfigErrors

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);
}
Also used : ElasticProfiles(com.thoughtworks.go.config.elastic.ElasticProfiles) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 45 with ConfigErrors

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));
}
Also used : ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)52 Test (org.junit.jupiter.api.Test)35 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)6 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)3 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Cloner (com.rits.cloning.Cloner)1 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 EnvironmentAgentConfig (com.thoughtworks.go.config.EnvironmentAgentConfig)1 EnvironmentConfig (com.thoughtworks.go.config.EnvironmentConfig)1 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)1 IgnoreTraversal (com.thoughtworks.go.config.IgnoreTraversal)1 Validatable (com.thoughtworks.go.config.Validatable)1 ElasticProfiles (com.thoughtworks.go.config.elastic.ElasticProfiles)1 GoConfigInvalidMergeException (com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1