use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldMarkAPreviousInvalidPartialAsValid_IfMainXMLSatisfiesTheDependency.
@Test
public void shouldMarkAPreviousInvalidPartialAsValid_IfMainXMLSatisfiesTheDependency() throws GitAPIException, IOException {
String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
PipelineConfig upstream = PipelineConfigMother.createPipelineConfig("upstream", "S", "J");
PartialConfig partialConfig = PartialConfigMother.pipelineWithDependencyMaterial("downstream", upstream, new RepoConfigOrigin(configRepo, "r2"));
partialConfigService.onSuccessPartialConfig(configRepo, partialConfig);
assertThat(cachedGoPartials.lastKnownPartials().contains(partialConfig)).isTrue();
assertThat(cachedGoPartials.lastValidPartials().isEmpty()).isTrue();
CruiseConfig originalConfig = cachedGoConfig.loadForEditing();
CruiseConfig editedConfig = GoConfigMother.deepClone(originalConfig);
editedConfig.addPipeline("default", upstream);
ConfigSaveState state = cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(editedConfig, 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(editedConfig);
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());
RepoConfigOrigin origin = (RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin();
assertThat(origin.getRevision()).isEqualTo("r2");
assertThat(cachedGoPartials.lastKnownPartials().contains(partialConfig)).isTrue();
assertThat(cachedGoPartials.lastValidPartials().contains(partialConfig)).isTrue();
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class FullConfigSaveFlowTestBase method shouldEncryptPluginPropertiesOfFetchTask.
@Test
public void shouldEncryptPluginPropertiesOfFetchTask() throws Exception {
CruiseConfig cruiseConfig = loader.deserializeConfig(xml);
Configuration childFetchConfigBeforeEncryption = ((FetchPluggableArtifactTask) cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("child")).get(0).getJobs().get(0).tasks().get(0)).getConfiguration();
assertThat(childFetchConfigBeforeEncryption.getProperty("FetchProperty").getValue(), is("SECRET"));
assertThat(childFetchConfigBeforeEncryption.getProperty("FetchProperty").getEncryptedValue(), is(nullValue()));
assertThat(childFetchConfigBeforeEncryption.getProperty("FetchProperty").getConfigValue(), is("SECRET"));
GoConfigHolder configHolder = getImplementer().execute(new FullConfigUpdateCommand(cruiseConfig, goConfigService.configFileMd5()), new ArrayList<>(), "Upgrade");
Configuration childFetchConfigAfterEncryption = ((FetchPluggableArtifactTask) configHolder.configForEdit.pipelineConfigByName(new CaseInsensitiveString("child")).get(0).getJobs().get(0).tasks().get(0)).getConfiguration();
assertThat(childFetchConfigAfterEncryption.getProperty("FetchProperty").getValue(), is("SECRET"));
assertThat(childFetchConfigAfterEncryption.getProperty("FetchProperty").getEncryptedValue(), startsWith("AES:"));
assertThat(childFetchConfigAfterEncryption.getProperty("FetchProperty").getConfigValue(), is(nullValue()));
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldUpdateConfigWhenPartialsAreNotConfigured.
@Test
public void shouldUpdateConfigWhenPartialsAreNotConfigured() throws GitAPIException, IOException {
String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
BasicCruiseConfig config = GoConfigMother.configWithPipelines("pipeline1");
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());
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldUpdateConfigWithNoValidPartialsAndInvalidKnownPartials.
@Test
public void shouldUpdateConfigWithNoValidPartialsAndInvalidKnownPartials() throws GitAPIException, IOException {
String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
PartialConfig invalidPartial = PartialConfigMother.invalidPartial("invalid", new RepoConfigOrigin(configRepo, "revision1"));
partialConfigService.onSuccessPartialConfig(configRepo, invalidPartial);
assertThat(cachedGoPartials.lastValidPartials().isEmpty()).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().isEmpty()).isTrue();
assertThat(cachedGoPartials.lastKnownPartials().contains(invalidPartial)).isTrue();
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class CachedGoConfigIntegrationTest method writeFullConfigWithLockShouldUpdateReloadStrategyToEnsureReloadIsSkippedInAbsenceOfConfigFileChanges.
@Test
public void writeFullConfigWithLockShouldUpdateReloadStrategyToEnsureReloadIsSkippedInAbsenceOfConfigFileChanges() throws GitAPIException, IOException {
BasicCruiseConfig config = GoConfigMother.configWithPipelines("pipeline1");
ConfigSaveState state = cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(config, goConfigService.configFileMd5()));
String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
assertThat(state).isEqualTo(ConfigSaveState.UPDATED);
cachedGoConfig.forceReload();
String gitShaAfterReload = configRepository.getCurrentRevCommit().getName();
assertThat(gitShaAfterReload).isEqualTo(gitShaAfterSave);
}
Aggregations