Search in sources :

Example 6 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class AdminRoleTest method shouldThrowExceptionIfRoleNameInStageAuthorizationDoesNotExist.

@Test
public void shouldThrowExceptionIfRoleNameInStageAuthorizationDoesNotExist() throws Exception {
    AdminRole role = new AdminRole(new CaseInsensitiveString("role2"));
    StageConfig stage = StageConfigMother.custom("ft", new AuthConfig(role));
    CruiseConfig config = new BasicCruiseConfig(new BasicPipelineConfigs(new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs(), stage)));
    role.validate(ConfigSaveValidationContext.forChain(config));
    ConfigErrors configErrors = role.errors();
    assertThat(configErrors.isEmpty(), is(false));
    assertThat(configErrors.on(AdminRole.NAME), is("Role \"role2\" does not exist."));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 7 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class BuildTaskTest method shouldErrorOutIfWorkingDirectoryIsOutsideTheCurrentWorkingDirectoryForTemplates.

@Test
public void shouldErrorOutIfWorkingDirectoryIsOutsideTheCurrentWorkingDirectoryForTemplates() {
    CruiseConfig config = GoConfigMother.configWithPipelines("pipeline-blah");
    BuildTask task = new AntTask();
    task.setWorkingDirectory("/blah");
    StageConfig stageConfig = StageConfigMother.manualStage("manualStage");
    stageConfig.getJobs().get(0).addTask(task);
    PipelineTemplateConfig template = new PipelineTemplateConfig(new CaseInsensitiveString("some-template"), stageConfig);
    config.addTemplate(template);
    List<ConfigErrors> errors = config.validateAfterPreprocess();
    assertThat(errors.size(), is(1));
    String message = "Task of job 'default' in stage 'manualStage' of template 'some-template' has path '/blah' which is outside the working directory.";
    assertThat(task.errors().on(BuildTask.WORKING_DIRECTORY), is(message));
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 8 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class MergeCruiseConfigTest method shouldCollectOriginErrorsFromMaterialConfigs_InMergedConfig.

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

Example 9 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class MergeCruiseConfigTest method shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned.

@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. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
    assertThat(allErrors.get(1).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
}
Also used : Cloner(com.rits.cloning.Cloner) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 10 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class GoConfigParallelGraphWalkerTest method shouldAddErrorsToRawCruiseConfigWhenTemplateHasErrors.

@Test
public void shouldAddErrorsToRawCruiseConfigWhenTemplateHasErrors() {
    CruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
    cruiseConfig.getTemplates().add(new PipelineTemplateConfig(new CaseInsensitiveString("invalid template name"), new StageConfig(new CaseInsensitiveString("stage-1"), new JobConfigs(new JobConfig("job-1")))));
    PipelineConfig pipelineWithTemplate = new PipelineConfig(new CaseInsensitiveString("pipeline-with-template"), MaterialConfigsMother.defaultMaterialConfigs());
    pipelineWithTemplate.setTemplateName(new CaseInsensitiveString("invalid template name"));
    cruiseConfig.getGroups().get(0).add(pipelineWithTemplate);
    CruiseConfig rawCruiseConfig = new Cloner().deepClone(cruiseConfig);
    MagicalGoConfigXmlLoader.validate(cruiseConfig);
    cruiseConfig.copyErrorsTo(rawCruiseConfig);
    ConfigErrors templateErrors = rawCruiseConfig.getTemplateByName(new CaseInsensitiveString("invalid template name")).errors();
    assertThat(templateErrors.getAll().size(), is(1));
    assertThat(templateErrors.getAll().get(0), is("Invalid template name 'invalid template name'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."));
}
Also used : Cloner(com.rits.cloning.Cloner) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Aggregations

ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)23 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 Cloner (com.rits.cloning.Cloner)2 IOException (java.io.IOException)2 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 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidMergeException (com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 UpdateEnvironmentsCommand (com.thoughtworks.go.config.update.UpdateEnvironmentsCommand)1 UpdateResourceCommand (com.thoughtworks.go.config.update.UpdateResourceCommand)1