Search in sources :

Example 1 with ConfigErrors

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

the class AdminRoleTest method shouldAddValidationErrorIfRoleNameInPipelinesAuthorizationDoesNotExist_PipelineConfigSaveValidationContext.

@Test
public void shouldAddValidationErrorIfRoleNameInPipelinesAuthorizationDoesNotExist_PipelineConfigSaveValidationContext() throws Exception {
    AdminRole role = new AdminRole(new CaseInsensitiveString("role2"));
    PipelineConfig pipelineConfig = new PipelineConfig();
    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.Test)

Example 2 with ConfigErrors

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

the class GoConfigInvalidMergeException method allErrorsToString.

private static String allErrorsToString(List<ConfigErrors> allErrors, String summary) {
    if (allErrors == null || allErrors.size() == 0)
        // should never be
        return "Error list empty";
    StringBuilder b = new StringBuilder();
    b.append(allErrors.size()).append("+ errors :: ");
    for (ConfigErrors e : allErrors) {
        b.append(e.firstError()).append(";; ");
    }
    return b.toString();
}
Also used : ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 3 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 4 with ConfigErrors

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

the class EnvironmentAgentValidator method validate.

public void validate(CruiseConfig cruiseConfig) throws Exception {
    List<ConfigErrors> errors = validateConfig(cruiseConfig);
    List<String> errorMessages = new ArrayList<>();
    for (ConfigErrors error : errors) {
        errorMessages.addAll(error.getAll());
    }
    if (!errors.isEmpty())
        throw new RuntimeException(StringUtils.join(errorMessages, ", "));
}
Also used : ArrayList(java.util.ArrayList) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 5 with ConfigErrors

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

the class GoFileConfigDataSourceTest method shouldNotRetryConfigSaveWhenConfigRepoIsNotSetup.

@Test
public void shouldNotRetryConfigSaveWhenConfigRepoIsNotSetup() throws Exception {
    MagicalGoConfigXmlLoader loader = mock(MagicalGoConfigXmlLoader.class);
    MagicalGoConfigXmlWriter writer = mock(MagicalGoConfigXmlWriter.class);
    GoConfigMigration migration = mock(GoConfigMigration.class);
    ServerHealthService serverHealthService = mock(ServerHealthService.class);
    CachedGoPartials cachedGoPartials = mock(CachedGoPartials.class);
    ConfigRepository configRepository = mock(ConfigRepository.class);
    dataSource = new GoFileConfigDataSource(migration, configRepository, systemEnvironment, timeProvider, mock(ServerVersion.class), loader, writer, serverHealthService, cachedGoPartials, null, null, null, null);
    final String pipelineName = UUID.randomUUID().toString();
    BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines(pipelineName);
    ConfigErrors configErrors = new ConfigErrors();
    configErrors.add("key", "some error");
    when(loader.loadConfigHolder(Matchers.any(String.class))).thenThrow(new GoConfigInvalidException(cruiseConfig, configErrors.firstError()));
    try {
        dataSource.writeWithLock(new UpdateConfigCommand() {

            @Override
            public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
                cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(pipelineName)).clear();
                return cruiseConfig;
            }
        }, new GoConfigHolder(cruiseConfig, cruiseConfig));
        fail("expected the test to fail");
    } catch (Exception e) {
        verifyZeroInteractions(configRepository);
        verifyZeroInteractions(serverHealthService);
        verify(loader, times(1)).loadConfigHolder(Matchers.any(String.class), Matchers.any(MagicalGoConfigXmlLoader.Callback.class));
    }
}
Also used : ConfigRepository(com.thoughtworks.go.service.ConfigRepository) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ExpectedException(org.junit.rules.ExpectedException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) IOException(java.io.IOException) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Aggregations

ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)47 Test (org.junit.jupiter.api.Test)32 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)6 Test (org.junit.Test)5 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)4 ArrayList (java.util.ArrayList)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)2 IOException (java.io.IOException)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 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidMergeException (com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException)1