use of com.thoughtworks.go.config.update.FullConfigUpdateCommand 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 = GoConfigMother.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()).isEqualTo(originalConfig);
assertThat(gitShaAfterSave).isEqualTo(gitShaBeforeSave);
assertThat(cachedGoConfig.loadForEditing().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
assertThat(cachedGoConfig.currentConfig().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
assertThat(configXmlFromConfigFolder).isEqualTo(configRepository.getCurrentRevision().getContent());
RepoConfigOrigin origin = (RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin();
assertThat(origin.getRevision()).isEqualTo("r1");
}
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldUpdateConfigWithValidPartialsAndInvalidKnownPartials.
@Test
public void shouldUpdateConfigWithValidPartialsAndInvalidKnownPartials() throws GitAPIException, IOException {
String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
PartialConfig validPartial = PartialConfigMother.withPipeline("remote_pipeline", new RepoConfigOrigin(configRepo, "revision1"));
PartialConfig invalidPartial = PartialConfigMother.invalidPartial("invalid", new RepoConfigOrigin(configRepo, "revision2"));
partialConfigService.onSuccessPartialConfig(configRepo, validPartial);
partialConfigService.onSuccessPartialConfig(configRepo, invalidPartial);
assertThat(cachedGoPartials.lastValidPartials().contains(validPartial)).isTrue();
assertThat(cachedGoPartials.lastKnownPartials().contains(invalidPartial)).isTrue();
CruiseConfig config = GoConfigMother.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).isEqualTo(ConfigSaveState.UPDATED);
assertThat(cachedGoConfig.loadForEditing()).isEqualTo(config);
assertThat(gitShaAfterSave).isNotEqualTo(gitShaBeforeSave);
assertThat(cachedGoConfig.loadForEditing().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
assertThat(cachedGoConfig.currentConfig().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
assertThat(configXmlFromConfigFolder).isEqualTo(configRepository.getCurrentRevision().getContent());
assertThat(cachedGoPartials.lastValidPartials().contains(validPartial)).isTrue();
assertThat(cachedGoPartials.lastKnownPartials().contains(invalidPartial)).isTrue();
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class FullConfigSaveFlowTestBase method shouldEncryptPluginPropertiesOfPublishTask.
@Test
public void shouldEncryptPluginPropertiesOfPublishTask() throws Exception {
CruiseConfig cruiseConfig = loader.deserializeConfig(xml);
Configuration ancestorPluggablePublishAftifactConfigBeforeEncryption = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("ancestor")).getExternalArtifactConfigs().get(0).getConfiguration();
assertThat(ancestorPluggablePublishAftifactConfigBeforeEncryption.getProperty("Image").getValue(), is("IMAGE_SECRET"));
assertThat(ancestorPluggablePublishAftifactConfigBeforeEncryption.getProperty("Image").getEncryptedValue(), is(nullValue()));
assertThat(ancestorPluggablePublishAftifactConfigBeforeEncryption.getProperty("Image").getConfigValue(), is("IMAGE_SECRET"));
GoConfigHolder configHolder = getImplementer().execute(new FullConfigUpdateCommand(cruiseConfig, goConfigService.configFileMd5()), new ArrayList<>(), "Upgrade");
Configuration ancestorPluggablePublishAftifactConfigAfterEncryption = configHolder.configForEdit.pipelineConfigByName(new CaseInsensitiveString("ancestor")).getExternalArtifactConfigs().get(0).getConfiguration();
assertThat(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getValue(), is("IMAGE_SECRET"));
assertThat(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getEncryptedValue(), startsWith("AES:"));
assertThat(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getConfigValue(), is(nullValue()));
// verify xml on disk contains encrypted Image plugin property
assertThat(configHelper.getCurrentXml(), containsString(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getEncryptedValue()));
// verify xml from GoConfigHolder contains encrypted Image plugin property
assertThat(getImplementer().toXmlString(configHolder.configForEdit), containsString(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getEncryptedValue()));
}
Aggregations