Search in sources :

Example 46 with ConfigErrors

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

the class AdminRoleTest method shouldAddValidationErrorWithPipelineNameIfRoleNameInPipelinesAuthorizationDoesNotExist_PipelineConfigSaveValidationContext.

@Test
public void shouldAddValidationErrorWithPipelineNameIfRoleNameInPipelinesAuthorizationDoesNotExist_PipelineConfigSaveValidationContext() {
    AdminRole role = new AdminRole(new CaseInsensitiveString("role2"));
    PipelineConfig pipelineConfig = new PipelineConfig();
    pipelineConfig.setName("foo");
    PipelineConfigs pipelinesConfig = new BasicPipelineConfigs(new Authorization(new ViewConfig(role)), pipelineConfig);
    CruiseConfig config = new BasicCruiseConfig(pipelinesConfig);
    role.validate(PipelineConfigSaveValidationContext.forChain(true, "group", config, pipelineConfig));
    ConfigErrors errors = role.errors();
    assertThat(errors.isEmpty(), is(false));
    assertThat(errors.on(AdminRole.NAME), is("Role \"role2\" does not exist."));
}
Also used : ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.jupiter.api.Test)

Example 47 with ConfigErrors

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

the class PipelineConfigValidationTest method shouldFailValidateWhenUpstreamStageForDependencyMaterialDoesNotExist.

@Test
void shouldFailValidateWhenUpstreamStageForDependencyMaterialDoesNotExist() {
    String upstreamPipeline = "upstream";
    String upstreamStage = "non-existant";
    PipelineConfig upstream = GoConfigMother.createPipelineConfigWithMaterialConfig(upstreamPipeline, git("url"));
    PipelineConfig pipelineConfig = GoConfigMother.createPipelineConfigWithMaterialConfig("downstream", new DependencyMaterialConfig(new CaseInsensitiveString(upstreamPipeline), new CaseInsensitiveString(upstreamStage)));
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(pipelineConfig, upstream));
    boolean isValid = pipelineConfig.validateTree(PipelineConfigSaveValidationContext.forChain(true, cruiseConfig.getGroups().first().getGroup(), cruiseConfig, pipelineConfig));
    assertThat(isValid).isFalse();
    ConfigErrors materialErrors = pipelineConfig.materialConfigs().first().errors();
    assertThat(materialErrors.isEmpty()).isFalse();
    assertThat(materialErrors.firstError()).isEqualTo("Stage with name 'non-existant' does not exist on pipeline 'upstream', it is being referred to from pipeline 'downstream' (cruise-config.xml)");
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.jupiter.api.Test)

Example 48 with ConfigErrors

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

the class PipelineConfigValidationTest method shouldFailValidateWhenUpstreamPipelineForDependencyMaterialDoesNotExist.

@Test
void shouldFailValidateWhenUpstreamPipelineForDependencyMaterialDoesNotExist() {
    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).isFalse();
    ConfigErrors materialErrors = pipelineConfig.materialConfigs().first().errors();
    assertThat(materialErrors.isEmpty()).isFalse();
    assertThat(materialErrors.firstError()).isEqualTo("Pipeline with name 'non-existant' does not exist, it is defined as a dependency for pipeline 'pipeline' (cruise-config.xml)");
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.jupiter.api.Test)

Example 49 with ConfigErrors

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

the class MaterialConfigsTest method shouldNotAllowMultipleDependenciesForTheSamePipelines.

@Test
public void shouldNotAllowMultipleDependenciesForTheSamePipelines() throws Exception {
    CruiseConfig config = GoConfigMother.configWithPipelines("pipeline1", "pipeline2", "pipeline3", "go");
    DependencyMaterialConfig dependencyMaterial = new DependencyMaterialConfig(new CaseInsensitiveString("pipeline2"), new CaseInsensitiveString("stage"));
    DependencyMaterialConfig duplicateDependencyMaterial = new DependencyMaterialConfig(new CaseInsensitiveString("pipeline2"), new CaseInsensitiveString("stage"));
    MaterialConfigs materialConfigs = new MaterialConfigs(dependencyMaterial, duplicateDependencyMaterial);
    ValidationContext validationContext = ConfigSaveValidationContext.forChain(config);
    materialConfigs.validate(validationContext);
    ConfigErrors errors = duplicateDependencyMaterial.errors();
    assertThat(errors.isEmpty(), is(false));
    assertThat(errors.on("pipelineStageName"), is("A pipeline can depend on each upstream pipeline only once. Remove one of the occurrences of 'pipeline2' from the current pipeline dependencies."));
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.jupiter.api.Test)

Example 50 with ConfigErrors

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

the class TrackingToolTest method shouldEnsureTrackingToolLinkContainsIDForTheMatchingRegexGroup.

@Test
public void shouldEnsureTrackingToolLinkContainsIDForTheMatchingRegexGroup() {
    TrackingTool trackingTool = new TrackingTool("http://no-id.com", "some-regex");
    trackingTool.validate(null);
    ConfigErrors configErrors = trackingTool.errors();
    List<String> errors = configErrors.getAllOn(TrackingTool.LINK);
    assertThat(errors.size(), is(1));
    assertThat(errors, hasItem("Link must be a URL containing '${ID}'. Go will replace the string '${ID}' with the first matched group from the regex at run-time."));
}
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