Search in sources :

Example 16 with ConfigErrors

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

the class ConfigReposConfig method getAllErrors.

public ConfigErrors getAllErrors() {
    ConfigErrors configErrors = new ConfigErrors();
    configErrors.addAll(errors);
    for (ConfigRepoConfig repoConfig : this) {
        configErrors.addAll(repoConfig.errors());
    }
    return configErrors;
}
Also used : ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 17 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 18 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)

Example 19 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.Test)

Example 20 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";
        }

        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 : StringContains.containsString(org.hamcrest.core.StringContains.containsString) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Aggregations

ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)26 Test (org.junit.Test)17 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