use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldRemoveCorrespondingRemotePipelinesFromCachedGoConfigIfTheConfigRepoIsDeleted.
@Test
public void shouldRemoveCorrespondingRemotePipelinesFromCachedGoConfigIfTheConfigRepoIsDeleted() {
final ConfigRepoConfig repoConfig1 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url1"), XmlPartialConfigProvider.providerName);
final ConfigRepoConfig repoConfig2 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url2"), XmlPartialConfigProvider.providerName);
goConfigService.updateConfig(new UpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
cruiseConfig.getConfigRepos().add(repoConfig1);
cruiseConfig.getConfigRepos().add(repoConfig2);
return cruiseConfig;
}
});
PartialConfig partialConfigInRepo1 = PartialConfigMother.withPipeline("pipeline_in_repo1", new RepoConfigOrigin(repoConfig1, "repo1_r1"));
PartialConfig partialConfigInRepo2 = PartialConfigMother.withPipeline("pipeline_in_repo2", new RepoConfigOrigin(repoConfig2, "repo2_r1"));
goPartialConfig.onSuccessPartialConfig(repoConfig1, partialConfigInRepo1);
goPartialConfig.onSuccessPartialConfig(repoConfig2, partialConfigInRepo2);
// introduce an invalid change in repo1 so that there is a server health message corresponding to it
PartialConfig invalidPartialInRepo1Revision2 = PartialConfigMother.invalidPartial("pipeline_in_repo1", new RepoConfigOrigin(repoConfig1, "repo1_r2"));
goPartialConfig.onSuccessPartialConfig(repoConfig1, invalidPartialInRepo1Revision2);
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("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: url1 at repo1_r2"));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(true));
int countBeforeDeletion = cachedGoConfig.currentConfig().getConfigRepos().size();
ConfigSaveState configSaveState = cachedGoConfig.writeWithLock(new UpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
cruiseConfig.getConfigRepos().remove(repoConfig1);
return cruiseConfig;
}
});
assertThat(configSaveState, is(ConfigSaveState.UPDATED));
assertThat(cachedGoConfig.currentConfig().getConfigRepos().size(), is(countBeforeDeletion - 1));
assertThat(cachedGoConfig.currentConfig().getConfigRepos().contains(repoConfig2), is(true));
assertThat(cachedGoConfig.currentConfig().getAllPipelineNames().contains(new CaseInsensitiveString("pipeline_in_repo1")), is(false));
assertThat(cachedGoConfig.currentConfig().getAllPipelineNames().contains(new CaseInsensitiveString("pipeline_in_repo2")), is(true));
assertThat(cachedGoPartials.lastKnownPartials().size(), is(1));
assertThat(((RepoConfigOrigin) cachedGoPartials.lastKnownPartials().get(0).getOrigin()).getMaterial().getFingerprint().equals(repoConfig2.getMaterialConfig().getFingerprint()), is(true));
assertThat(cachedGoPartials.lastKnownPartials().stream().filter(new Predicate<PartialConfig>() {
@Override
public boolean test(PartialConfig item) {
return ((RepoConfigOrigin) item.getOrigin()).getMaterial().getFingerprint().equals(repoConfig1.getMaterialConfig().getFingerprint());
}
}).findFirst().orElse(null), is(nullValue()));
assertThat(cachedGoPartials.lastValidPartials().size(), is(1));
assertThat(((RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin()).getMaterial().getFingerprint().equals(repoConfig2.getMaterialConfig().getFingerprint()), is(true));
assertThat(cachedGoPartials.lastValidPartials().stream().filter(new Predicate<PartialConfig>() {
@Override
public boolean test(PartialConfig item) {
return ((RepoConfigOrigin) item.getOrigin()).getMaterial().getFingerprint().equals(repoConfig1.getMaterialConfig().getFingerprint());
}
}).findFirst().orElse(null), is(nullValue()));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(true));
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldUpdateConfigWhenPartialsAreConfigured.
@Test
public void shouldUpdateConfigWhenPartialsAreConfigured() throws GitAPIException, IOException {
String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
PartialConfig validPartial = PartialConfigMother.withPipeline("remote_pipeline", new RepoConfigOrigin(configRepo, "revision1"));
goPartialConfig.onSuccessPartialConfig(configRepo, validPartial);
assertThat(cachedGoPartials.lastValidPartials().contains(validPartial), is(true));
assertThat(cachedGoPartials.lastKnownPartials().contains(validPartial), is(true));
CruiseConfig config = new Cloner().deepClone(cachedGoConfig.loadForEditing());
config.addEnvironment(UUID.randomUUID().toString());
ConfigSaveState state = cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(config, goConfigService.configFileMd5()));
String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
assertThat(state, is(ConfigSaveState.UPDATED));
assertThat(cachedGoConfig.loadForEditing(), is(config));
assertNotEquals(gitShaBeforeSave, gitShaAfterSave);
assertThat(cachedGoConfig.loadForEditing().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
assertThat(cachedGoConfig.currentConfig().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
assertThat(configXmlFromConfigFolder, is(configRepository.getCurrentRevision().getContent()));
assertThat(cachedGoPartials.lastValidPartials().contains(validPartial), is(true));
assertThat(cachedGoPartials.lastKnownPartials().contains(validPartial), is(true));
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldMarkAPartialAsValidIfItBecomesValidBecauseOfNewerChangesInMainXml_GitMergeWorkflow.
@Test
public void shouldMarkAPartialAsValidIfItBecomesValidBecauseOfNewerChangesInMainXml_GitMergeWorkflow() {
final String upstream = UUID.randomUUID().toString();
String remoteDownstream = "remote-downstream";
setupExternalConfigRepoWithDependencyMaterialOnPipelineInMainXml(upstream, remoteDownstream);
PartialConfig partialWithStageRenamed = new Cloner().deepClone(goPartialConfig.lastPartials().get(0));
PipelineConfig pipelineInRemoteConfigRepo = partialWithStageRenamed.getGroups().get(0).getPipelines().get(0);
pipelineInRemoteConfigRepo.materialConfigs().getDependencyMaterial().setStageName(new CaseInsensitiveString("new_name"));
partialWithStageRenamed.setOrigin(new RepoConfigOrigin(configRepo, "r2"));
goPartialConfig.onSuccessPartialConfig(configRepo, partialWithStageRenamed);
final String md5 = cachedGoConfig.currentConfig().getMd5();
// some random unrelated change to force a git merge workflow
cachedGoConfig.writeWithLock(new NoOverwriteUpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
cruiseConfig.server().setCommandRepositoryLocation("new_location");
return cruiseConfig;
}
@Override
public String unmodifiedMd5() {
return md5;
}
});
ConfigSaveState saveState = cachedGoConfig.writeWithLock(new NoOverwriteUpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(upstream)).getFirstStageConfig().setName(new CaseInsensitiveString("new_name"));
return cruiseConfig;
}
@Override
public String unmodifiedMd5() {
return md5;
}
});
assertThat(saveState, is(ConfigSaveState.MERGED));
assertThat(cachedGoPartials.lastValidPartials().get(0).getGroups().first().get(0).materialConfigs().getDependencyMaterial().getStageName(), is(new CaseInsensitiveString("new_name")));
assertThat(goConfigService.getConfigForEditing().getPipelineConfigByName(new CaseInsensitiveString(upstream)).getFirstStageConfig().name(), is(new CaseInsensitiveString("new_name")));
assertThat(goConfigService.getCurrentConfig().getPipelineConfigByName(new CaseInsensitiveString(upstream)).getFirstStageConfig().name(), is(new CaseInsensitiveString("new_name")));
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldAllowFallbackMergeAndSaveWhenKnownPartialHasAnInvalidEnvironmentThatRefersToAnUnknownPipeline.
@Test
public void shouldAllowFallbackMergeAndSaveWhenKnownPartialHasAnInvalidEnvironmentThatRefersToAnUnknownPipeline() throws Exception {
cachedGoPartials.clear();
PartialConfig partialConfigWithInvalidEnvironment = PartialConfigMother.withEnvironment("env", new RepoConfigOrigin(configRepo, "revision1"));
goPartialConfig.onSuccessPartialConfig(configRepo, partialConfigWithInvalidEnvironment);
ConfigSaveState state = cachedGoConfig.writeWithLock(new UpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
cruiseConfig.server().setCommandRepositoryLocation("newlocation");
return cruiseConfig;
}
});
assertThat(state, is(ConfigSaveState.UPDATED));
assertThat(goConfigService.getCurrentConfig().server().getCommandRepositoryLocation(), is("newlocation"));
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials.
@Test
public void shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials() throws GitAPIException, IOException {
setupExternalConfigRepoWithDependencyMaterialOnPipelineInMainXml("upstream", "downstream");
String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
CruiseConfig originalConfig = cachedGoConfig.loadForEditing();
CruiseConfig editedConfig = new Cloner().deepClone(originalConfig);
editedConfig.getGroups().remove(editedConfig.findGroup("default"));
try {
cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(editedConfig, goConfigService.configFileMd5()));
fail("Expected the test to fail");
} catch (Exception e) {
String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
assertThat(cachedGoConfig.loadForEditing(), is(originalConfig));
assertEquals(gitShaBeforeSave, gitShaAfterSave);
assertThat(cachedGoConfig.loadForEditing().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
assertThat(cachedGoConfig.currentConfig().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
assertThat(configXmlFromConfigFolder, is(configRepository.getCurrentRevision().getContent()));
RepoConfigOrigin origin = (RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin();
assertThat(origin.getRevision(), is("r1"));
}
}
Aggregations