Search in sources :

Example 56 with PartialConfig

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

the class XmlPartialConfigProviderTest method shouldParseFileWithOneEnvironment.

@Test
public void shouldParseFileWithOneEnvironment() throws Exception {
    EnvironmentConfig env = EnvironmentConfigMother.environment("dev");
    File file = helper.addFileWithEnvironment("dev-env.gocd.xml", env);
    PartialConfig part = xmlPartialProvider.parseFile(file);
    EnvironmentsConfig loadedEnvs = part.getEnvironments();
    assertThat(loadedEnvs.size(), is(1));
    assertThat(loadedEnvs.get(0), is(env));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) File(java.io.File) Test(org.junit.Test)

Example 57 with PartialConfig

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

the class XmlPartialConfigProviderTest method shouldFailToLoadDirectoryWithNonXmlFormat.

@Test
public void shouldFailToLoadDirectoryWithNonXmlFormat() throws Exception {
    String content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<cruise xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"cruise-config.xsd\" schemaVersion=\"38\">\n" + // missing '<'
    "/cruise>";
    helper.writeFileWithContent("bad.gocd.xml", content);
    try {
        PartialConfig part = xmlPartialProvider.load(tmpFolder, mock(PartialConfigLoadContext.class));
    } catch (RuntimeException ex) {
        return;
    }
    fail("should have thrown");
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) Test(org.junit.Test)

Example 58 with PartialConfig

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

the class ConfigMaterialUpdaterIntegrationTest method shouldParseAndLoadValidPartialConfig.

@Test
public void shouldParseAndLoadValidPartialConfig() throws Exception {
    String fileName = "pipe1.gocd.xml";
    GoConfigMother mother = new GoConfigMother();
    PipelineConfig pipelineConfig = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
    configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    PartialConfig partial = goRepoConfigDataSource.latestPartialConfigForMaterial(materialConfig);
    assertNotNull(partial);
    assertThat(partial.getGroups().get(0).size(), is(1));
    assertThat(partial.getGroups().get(0).get(0), is(pipelineConfig));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother)

Example 59 with PartialConfig

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

the class ConfigMaterialUpdaterIntegrationTest method shouldParseAgainWhenChangesInMaterial.

@Test
public void shouldParseAgainWhenChangesInMaterial() throws Exception {
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    String revision = goRepoConfigDataSource.getRevisionAtLastAttempt(materialConfig);
    assertNotNull(revision);
    PartialConfig partial = goRepoConfigDataSource.latestPartialConfigForMaterial(materialConfig);
    hgRepo.commitAndPushFile("newFile.bla", "could be config file");
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    PartialConfig partial2 = goRepoConfigDataSource.latestPartialConfigForMaterial(materialConfig);
    assertNotSame(partial, partial2);
    assertThat("originsShouldDiffer", partial2.getOrigin(), is(not(partial.getOrigin())));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig)

Example 60 with PartialConfig

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

the class PipelineConfigServiceIntegrationTest method shouldPerformFullValidationNotJustEntitySpecificIfMergingKnownPartialsAsOtherAspectsOfAKnownPartialMightBeInvalid.

@Test
public void shouldPerformFullValidationNotJustEntitySpecificIfMergingKnownPartialsAsOtherAspectsOfAKnownPartialMightBeInvalid() throws Exception {
    PipelineConfig remoteDownstreamPipeline = partialConfig.getGroups().first().getPipelines().get(0);
    assertThat(goConfigService.getCurrentConfig().getAllPipelineNames().contains(remoteDownstreamPipeline.name()), is(true));
    String independentRemotePipeline = "independent-pipeline";
    assertThat(goConfigService.getCurrentConfig().getAllPipelineNames().contains(new CaseInsensitiveString(independentRemotePipeline)), is(true));
    // introduce an invalid change in the independent partial
    PartialConfig invalidIndependentPartial = PartialConfigMother.invalidPartial(independentRemotePipeline, new RepoConfigOrigin(repoConfig2, "repo2_r2"));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, invalidIndependentPartial);
    assertThat(((RepoConfigOrigin) cachedGoPartials.getValid(repoConfig2.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo2_r1"));
    assertThat(((RepoConfigOrigin) cachedGoPartials.getKnown(repoConfig2.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo2_r2"));
    assertThat(((RepoConfigOrigin) goConfigService.getCurrentConfig().getPipelineConfigByName(new CaseInsensitiveString(independentRemotePipeline)).getOrigin()).getRevision(), is("repo2_r1"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).size(), is(1));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0).getMessage(), is("Invalid Merged Configuration"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0).getDescription(), is("1+ errors :: Invalid stage 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.;;  -  Config-Repo: url2 at repo2_r2"));
    final CaseInsensitiveString upstreamStageRenamed = new CaseInsensitiveString("upstream_stage_renamed");
    partialConfig = PartialConfigMother.pipelineWithDependencyMaterial("remote-downstream", new PipelineConfig(pipelineConfig.name(), pipelineConfig.materialConfigs(), new StageConfig(upstreamStageRenamed, new JobConfigs())), new RepoConfigOrigin(repoConfig1, "repo1_r2"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, partialConfig);
    CruiseConfig currentConfig = goConfigService.getCurrentConfig();
    DependencyMaterialConfig dependencyMaterialForRemotePipelineInConfigCache = currentConfig.getPipelineConfigByName(remoteDownstreamPipeline.name()).materialConfigs().findDependencyMaterial(pipelineConfig.name());
    assertThat(dependencyMaterialForRemotePipelineInConfigCache.getStageName(), is(new CaseInsensitiveString("stage")));
    assertThat(((RepoConfigOrigin) currentConfig.getPipelineConfigByName(remoteDownstreamPipeline.name()).getOrigin()).getRevision(), is("repo1_r1"));
    assertThat(((RepoConfigOrigin) cachedGoPartials.getValid(repoConfig1.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo1_r1"));
    assertThat(((RepoConfigOrigin) cachedGoPartials.getKnown(repoConfig1.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo1_r2"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).size(), is(1));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).get(0).getMessage(), is("Invalid Merged Configuration"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).get(0).getDescription(), is(String.format("1+ errors :: Stage with name 'upstream_stage_renamed' does not exist on pipeline '%s', it is being referred to from pipeline 'remote-downstream' (url at repo1_r2);;  -  Config-Repo: url at repo1_r2", pipelineConfig.name())));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).size(), is(1));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0).getMessage(), is("Invalid Merged Configuration"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0).getDescription(), is("1+ errors :: Invalid stage 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.;;  -  Config-Repo: url2 at repo2_r2"));
    String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig);
    String md5 = CachedDigestUtils.md5Hex(xml);
    pipelineConfig.getFirstStageConfig().setName(new CaseInsensitiveString("upstream_stage_renamed"));
    pipelineConfigService.updatePipelineConfig(user, pipelineConfig, md5, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is(String.format("Validations failed for pipeline '%s'. " + "Error(s): [Merged update operation failed on VALID 2 partials. Falling back to using LAST KNOWN 2 partials. " + "Exception message was: [Validation failed. Stage with name 'stage' does not exist on pipeline '%s', " + "it is being referred to from pipeline 'remote-downstream' (url at repo1_r1)]" + System.lineSeparator() + "Merged config update operation failed using fallback LAST KNOWN 2 partials. " + "Exception message was: 1+ errors :: Invalid stage 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.;; ]. Please correct and resubmit.", pipelineConfig.name(), pipelineConfig.name())));
    assertThat(ErrorCollector.getAllErrors(pipelineConfig).isEmpty(), is(true));
    currentConfig = goConfigService.getCurrentConfig();
    assertThat(currentConfig.getAllPipelineNames().contains(remoteDownstreamPipeline.name()), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().equals(cachedGoPartials.lastValidPartials()), is(false));
    assertThat(currentConfig.getPipelineConfigByName(remoteDownstreamPipeline.name()).materialConfigs().findDependencyMaterial(pipelineConfig.name()).getStageName(), is(new CaseInsensitiveString("stage")));
    assertThat(currentConfig.getPipelineConfigByName(pipelineConfig.name()).getFirstStageConfig().name(), is(new CaseInsensitiveString("stage")));
    assertThat(((RepoConfigOrigin) currentConfig.getPipelineConfigByName(remoteDownstreamPipeline.name()).getOrigin()).getRevision(), is("repo1_r1"));
    assertThat(((RepoConfigOrigin) cachedGoPartials.getValid(repoConfig1.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo1_r1"));
    assertThat(((RepoConfigOrigin) cachedGoPartials.getKnown(repoConfig1.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo1_r2"));
    assertThat(((RepoConfigOrigin) currentConfig.getPipelineConfigByName(new CaseInsensitiveString(independentRemotePipeline)).getOrigin()).getRevision(), is("repo2_r1"));
    assertThat(((RepoConfigOrigin) cachedGoPartials.getValid(repoConfig2.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo2_r1"));
    assertThat(((RepoConfigOrigin) cachedGoPartials.getKnown(repoConfig2.getMaterialConfig().getFingerprint()).getOrigin()).getRevision(), is("repo2_r2"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).size(), is(1));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).get(0).getMessage(), is("Invalid Merged Configuration"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).get(0).getDescription(), is(String.format("1+ errors :: Stage with name 'upstream_stage_renamed' does not exist on pipeline '%s', it is being referred to from pipeline 'remote-downstream' (url at repo1_r2);;  -  Config-Repo: url at repo1_r2", pipelineConfig.name())));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).size(), is(1));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0).getMessage(), is("Invalid Merged Configuration"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0).getDescription(), is("1+ errors :: Invalid stage 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.;;  -  Config-Repo: url2 at repo2_r2"));
}
Also used : 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)

Aggregations

PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)70 Test (org.junit.Test)39 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)29 File (java.io.File)15 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)12 StringContains.containsString (org.hamcrest.core.StringContains.containsString)12 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)10 IOException (java.io.IOException)8 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 ExpectedException (org.junit.rules.ExpectedException)8 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)7 PipelineGroups (com.thoughtworks.go.domain.PipelineGroups)7 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)7 Cloner (com.rits.cloning.Cloner)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)6 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)5 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)4 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)4 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)3 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)3