use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldNotRetryConfigUpdateIfLastKnownPartialsAreEmpty_OnWriteFullConfigWithLock.
@Test
public void shouldNotRetryConfigUpdateIfLastKnownPartialsAreEmpty_OnWriteFullConfigWithLock() throws Exception {
List<PartialConfig> known = new ArrayList<>();
BasicCruiseConfig configForEdit = new BasicCruiseConfig();
MagicalGoConfigXmlLoader.setMd5(configForEdit, "md5");
FullConfigUpdateCommand updatingCommand = new FullConfigUpdateCommand(new BasicCruiseConfig(), "md5");
GoConfigHolder configHolder = new GoConfigHolder(new BasicCruiseConfig(), configForEdit);
when(cachedGoPartials.lastKnownPartials()).thenReturn(known);
when(fullConfigSaveNormalFlow.execute(updatingCommand, known, "loser_boozer")).thenThrow(new GoConfigInvalidException(configForEdit, "error"));
assertThatThrownBy(() -> dataSource.writeFullConfigWithLock(updatingCommand, configHolder)).isInstanceOf(RuntimeException.class);
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldReloadConfigUsingFullSaveNormalFlowWithLastValidPartialsIfUpdatingWithLastKnownPartialsFails_onLoad.
@Test
public void shouldReloadConfigUsingFullSaveNormalFlowWithLastValidPartialsIfUpdatingWithLastKnownPartialsFails_onLoad() throws Exception {
CruiseConfig cruiseConfig = new BasicCruiseConfig();
PartialConfigMother.withPipeline("P1");
List lastKnownPartials = Arrays.asList(PartialConfigMother.withPipeline("P1"));
List lastValidPartials = Arrays.asList(PartialConfigMother.withPipeline("P2"), PartialConfigMother.withPipeline("P3"));
GoConfigHolder goConfigHolder = new GoConfigHolder(cruiseConfig, cruiseConfig);
ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
when(systemEnvironment.getCruiseConfigFile()).thenReturn("");
when(goConfigFileReader.fileLocation()).thenReturn(new File(""));
when(goConfigFileReader.configXml()).thenReturn("config_xml");
when(xmlLoader.deserializeConfig("config_xml")).thenReturn(cruiseConfig);
when(cachedGoPartials.lastKnownPartials()).thenReturn(lastKnownPartials);
when(cachedGoPartials.lastValidPartials()).thenReturn(lastValidPartials);
when(fullConfigSaveNormalFlow.execute(commandArgumentCaptor.capture(), listArgumentCaptor.capture(), stringArgumentCaptor.capture())).thenThrow(new GoConfigInvalidException(null, Collections.emptyList())).thenReturn(goConfigHolder);
dataSource.reloadEveryTime();
GoConfigHolder configHolder = dataSource.load();
assertThat(configHolder, is(goConfigHolder));
assertThat(commandArgumentCaptor.getValue().configForEdit(), is(cruiseConfig));
assertThat(listArgumentCaptor.getValue(), is(lastValidPartials));
assertThat(stringArgumentCaptor.getValue(), is("Filesystem"));
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class FullConfigSaveNormalFlowTest method setup.
@BeforeEach
public void setup() throws Exception {
configForEdit = new BasicCruiseConfig();
updateConfigCommand = new FullConfigUpdateCommand(configForEdit, "md5");
loader = mock(MagicalGoConfigXmlLoader.class);
writer = mock(MagicalGoConfigXmlWriter.class);
document = mock(Document.class);
fileWriter = mock(GoConfigFileWriter.class);
timeProvider = mock(TimeProvider.class);
configRepository = mock(ConfigRepository.class);
cachedGoPartials = mock(CachedGoPartials.class);
configElementImplementationRegistry = mock(ConfigElementImplementationRegistry.class);
partials = new ArrayList<>();
flow = new FullConfigSaveNormalFlow(loader, writer, configElementImplementationRegistry, timeProvider, configRepository, cachedGoPartials, fileWriter);
when(writer.documentFrom(configForEdit)).thenReturn(document);
when(loader.preprocessAndValidate(configForEdit)).thenReturn(new BasicCruiseConfig());
when(writer.toString(document)).thenReturn("cruise_config");
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class GoConfigServiceTest method shouldIgnoreXmlEntitiesAndReplaceThemWithEmptyString_DuringPipelineGroupPartialSave.
@Test
public void shouldIgnoreXmlEntitiesAndReplaceThemWithEmptyString_DuringPipelineGroupPartialSave() throws Exception {
ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
File targetFile = TempFiles.createUniqueFile("somefile");
FileUtils.writeStringToFile(targetFile, "CONTENTS_OF_FILE", StandardCharsets.UTF_8);
cruiseConfig = new BasicCruiseConfig();
expectLoad(cruiseConfig);
new GoConfigMother().addPipelineWithGroup(cruiseConfig, "group_name", "pipeline1", "stage_name", "job_name");
expectLoadForEditing(cruiseConfig);
when(goConfigDao.md5OfConfigFile()).thenReturn("md5");
when(goConfigDao.updateFullConfig(commandArgumentCaptor.capture())).thenReturn(null);
GoConfigService.XmlPartialSaver partialSaver = goConfigService.groupSaver("group_name");
GoConfigValidity validity = partialSaver.saveXml(groupXmlWithEntity(targetFile.getAbsolutePath()), "md5");
PipelineConfigs group = commandArgumentCaptor.getValue().configForEdit().findGroup("group_name");
PipelineConfig pipeline = group.findBy(new CaseInsensitiveString("pipeline1"));
assertThat(validity.isValid(), Matchers.is(true));
String entityValue = pipeline.getParams().getParamNamed("foo").getValue();
assertThat(entityValue, not(containsString("CONTENTS_OF_FILE")));
assertThat(entityValue, isEmptyString());
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand 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"));
partialConfigService.onSuccessPartialConfig(configRepo, validPartial);
assertThat(cachedGoPartials.lastValidPartials().contains(validPartial)).isTrue();
assertThat(cachedGoPartials.lastKnownPartials().contains(validPartial)).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(validPartial)).isTrue();
}
Aggregations