Search in sources :

Example 11 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class GoPartialConfigIntegrationTest method shouldMarkAnInvalidKnownPartialAsValidWhenLoadingAnotherPartialMakesThisOneValid_InterConfigRepoDependency.

@Test
public void shouldMarkAnInvalidKnownPartialAsValidWhenLoadingAnotherPartialMakesThisOneValid_InterConfigRepoDependency() {
    ConfigRepoConfig repoConfig3 = new ConfigRepoConfig(new GitMaterialConfig("url3"), "plugin");
    configHelper.addConfigRepo(repoConfig3);
    PartialConfig repo1 = PartialConfigMother.withPipeline("p1_repo1", new RepoConfigOrigin(repoConfig1, "1"));
    PartialConfig repo2 = PartialConfigMother.withPipeline("p2_repo2", new RepoConfigOrigin(repoConfig2, "1"));
    PartialConfig repo3 = PartialConfigMother.withPipeline("p3_repo3", new RepoConfigOrigin(repoConfig3, "1"));
    PipelineConfig p1 = repo1.getGroups().first().getPipelines().get(0);
    PipelineConfig p2 = repo2.getGroups().first().getPipelines().get(0);
    PipelineConfig p3 = repo3.getGroups().first().getPipelines().get(0);
    p2.addMaterialConfig(new DependencyMaterialConfig(p1.name(), p1.first().name()));
    p2.addMaterialConfig(new DependencyMaterialConfig(p3.name(), p3.first().name()));
    p1.addMaterialConfig(new DependencyMaterialConfig(p3.name(), p3.first().name()));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, repo2);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p2.name()), is(false));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(false));
    ServerHealthState healthStateForInvalidConfigMerge = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0);
    assertThat(healthStateForInvalidConfigMerge.getMessage(), is("Invalid Merged Configuration"));
    assertThat(healthStateForInvalidConfigMerge.getDescription(), is("3+ errors :: Pipeline "p1_repo1" does not exist. It is used from pipeline "p2_repo2".;; Pipeline with name 'p1_repo1' does not exist, it is defined as a dependency for pipeline 'p2_repo2' (url2 at 1);; Pipeline with name 'p3_repo3' does not exist, it is defined as a dependency for pipeline 'p2_repo2' (url2 at 1);;  -  Config-Repo: url2 at 1"));
    assertThat(healthStateForInvalidConfigMerge.getLogLevel(), is(HealthStateLevel.ERROR));
    assertThat(cachedGoPartials.lastValidPartials().isEmpty(), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(1));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo1), is(false));
    goPartialConfig.onSuccessPartialConfig(repoConfig3, repo3);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p3.name()), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p2.name()), is(false));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p1.name()), is(false));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig3)).isEmpty(), is(true));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(1));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo2), is(false));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo3), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(2));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo3), is(true));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, repo1);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p1.name()), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p2.name()), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p3.name()), is(true));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(3));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo1), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo3), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(3));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo1), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo3), is(true));
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 12 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldUnSetErrorHealthStateWhenMergePasses.

@Test
public void shouldUnSetErrorHealthStateWhenMergePasses() throws IOException {
    ConfigRepoConfig configRepo = configWatchList.getCurrentConfigRepos().get(0);
    checkinPartial("config_repo_with_invalid_partial/bad_partial.gocd.xml");
    repoConfigDataSource.onCheckoutComplete(configRepo.getMaterialConfig(), externalConfigRepo, latestCommit);
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(configRepo)).isEmpty(), is(false));
    //fix partial
    deletePartial("bad_partial.gocd.xml");
    repoConfigDataSource.onCheckoutComplete(configRepo.getMaterialConfig(), externalConfigRepo, latestCommit);
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(configRepo)).isEmpty(), is(true));
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig)

Example 13 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldSetErrorHealthStateWhenMergeFails.

@Test
public void shouldSetErrorHealthStateWhenMergeFails() throws IOException {
    checkinPartial("config_repo_with_invalid_partial");
    ConfigRepoConfig configRepo = configWatchList.getCurrentConfigRepos().get(0);
    repoConfigDataSource.onCheckoutComplete(configRepo.getMaterialConfig(), externalConfigRepo, latestCommit);
    List<ServerHealthState> messageForInvalidMerge = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(configRepo));
    assertThat(messageForInvalidMerge.isEmpty(), is(false));
    assertThat(messageForInvalidMerge.get(0).getDescription().contains("Pipeline 'pipeline_with_no_stage' does not have any stages configured"), is(true));
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Example 14 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class BuildCauseProducerServiceTest method manualTrigger_shouldRequestUpdateOfNewMaterials_WhenPipelineConfigInConfigRepo.

@Test
public void manualTrigger_shouldRequestUpdateOfNewMaterials_WhenPipelineConfigInConfigRepo() {
    HgMaterial material1 = new HgMaterial("url", null);
    HgMaterial material2 = new HgMaterial("url2", null);
    HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
    HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
    pipelineConfig.addMaterialConfig(materialConfig1);
    pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig1, "plug"), "revision1"));
    when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
    when(materialConfigConverter.toMaterial(materialConfig2)).thenReturn(material2);
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
    verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
    // updated pipeline config
    PipelineConfig pipelineConfig1 = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs());
    pipelineConfig1.addMaterialConfig(materialConfig1);
    pipelineConfig1.addMaterialConfig(materialConfig2);
    when(goConfigService.pipelineConfigNamed(pipelineConfig.name())).thenReturn(pipelineConfig1);
    when(goConfigService.hasPipelineNamed(pipelineConfig.name())).thenReturn(true);
    MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
    statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
    verify(goConfigService, times(2)).pipelineConfigNamed(pipelineConfig.name());
    verify(mockMaterialUpdateService, times(1)).updateMaterial(material1);
    verify(mockMaterialUpdateService, times(1)).updateMaterial(material2);
    statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material2, 0));
    verify(mockMaterialUpdateStatusNotifier).removeListenerFor(pipelineConfig1);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialUpdateStatusListener(com.thoughtworks.go.server.materials.MaterialUpdateStatusListener) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) HashMap(java.util.HashMap) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 15 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class BuildCauseProducerServiceTest method manualTrigger_shouldNotUpdatePipelineConfigWhenConfigRepoIsNotInMaterials.

@Test
public void manualTrigger_shouldNotUpdatePipelineConfigWhenConfigRepoIsNotInMaterials() {
    HgMaterial material1 = new HgMaterial("url", null);
    HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
    HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
    pipelineConfig.addMaterialConfig(materialConfig1);
    pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig2, "plug"), "revision1"));
    when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
    verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
    MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
    statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
    verify(mockMaterialUpdateStatusNotifier).removeListenerFor(pipelineConfig);
    verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
}
Also used : MaterialUpdateStatusListener(com.thoughtworks.go.server.materials.MaterialUpdateStatusListener) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) HashMap(java.util.HashMap) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) Test(org.junit.Test)

Aggregations

ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)54 Test (org.junit.Test)34 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)32 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)27 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)10 ConfigReposConfig (com.thoughtworks.go.config.remote.ConfigReposConfig)8 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)8 Before (org.junit.Before)8 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)6 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)6 File (java.io.File)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 AbstractMaterialConfig (com.thoughtworks.go.config.materials.AbstractMaterialConfig)4 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)4 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)4 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)4 FileConfigOrigin (com.thoughtworks.go.config.remote.FileConfigOrigin)4 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3