use of com.thoughtworks.go.config.remote.PartialConfig in project gocd by gocd.
the class ConfigConverterTest method shouldConvertPartialConfigWithGroupsAndEnvironments.
@Test
public void shouldConvertPartialConfigWithGroupsAndEnvironments() {
CRPipeline pipeline = new CRPipeline("pipename", "group", "label", LOCK_VALUE_LOCK_ON_FAILURE, trackingTool, null, timer, environmentVariables, materials, stages, null, parameters);
ArrayList<String> agents = new ArrayList<>();
agents.add("12");
ArrayList<String> pipelineNames = new ArrayList<>();
pipelineNames.add("pipename");
CREnvironment crEnvironment = new CREnvironment("dev", environmentVariables, agents, pipelineNames);
CRParseResult crPartialConfig = new CRParseResult();
crPartialConfig.getEnvironments().add(crEnvironment);
crPartialConfig.getPipelines().add(pipeline);
PartialConfig partialConfig = configConverter.toPartialConfig(crPartialConfig, context);
assertThat(partialConfig.getGroups().size(), is(1));
assertThat(partialConfig.getEnvironments().size(), is(1));
}
use of com.thoughtworks.go.config.remote.PartialConfig in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldNotRetryConfigUpdateIfLastKnownPartialsAreEmpty_OnWriteFullConfigWithLock.
@Test(expected = RuntimeException.class)
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);
CachedGoPartials cachedGoPartials = mock(CachedGoPartials.class);
GoFileConfigDataSource source = new GoFileConfigDataSource(null, null, systemEnvironment, null, null, null, null, null, cachedGoPartials, fullConfigSaveMergeFlow, fullConfigSaveNormalFlow);
stub(cachedGoPartials.lastKnownPartials()).toReturn(known);
when(fullConfigSaveNormalFlow.execute(updatingCommand, known, "loser_boozer")).thenThrow(new GoConfigInvalidException(configForEdit, "error"));
source.writeFullConfigWithLock(updatingCommand, configHolder);
}
use of com.thoughtworks.go.config.remote.PartialConfig in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldUpdateConfigWithLastKnownPartials_OnWriteFullConfigWithLock.
@Test
public void shouldUpdateConfigWithLastKnownPartials_OnWriteFullConfigWithLock() throws Exception {
BasicCruiseConfig configForEdit = new BasicCruiseConfig();
MagicalGoConfigXmlLoader.setMd5(configForEdit, "md5");
FullConfigUpdateCommand updatingCommand = new FullConfigUpdateCommand(new BasicCruiseConfig(), "md5");
GoConfigHolder configHolder = new GoConfigHolder(new BasicCruiseConfig(), configForEdit);
List<PartialConfig> lastKnownPartials = mock(List.class);
CachedGoPartials cachedGoPartials = mock(CachedGoPartials.class);
GoFileConfigDataSource source = new GoFileConfigDataSource(null, null, null, null, null, null, null, null, cachedGoPartials, fullConfigSaveMergeFlow, fullConfigSaveNormalFlow);
stub(cachedGoPartials.lastKnownPartials()).toReturn(lastKnownPartials);
stub(fullConfigSaveNormalFlow.execute(Matchers.any(FullConfigUpdateCommand.class), Matchers.any(List.class), Matchers.any(String.class))).toReturn(new GoConfigHolder(new BasicCruiseConfig(), new BasicCruiseConfig()));
source.writeFullConfigWithLock(updatingCommand, configHolder);
verify(fullConfigSaveNormalFlow).execute(updatingCommand, lastKnownPartials, "loser_boozer");
}
use of com.thoughtworks.go.config.remote.PartialConfig in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldFallbackToLastKnownValidPartialsForValidationWhenConfigSaveWithLastKnownPartialsWithMainConfigFails.
@Test
public void shouldFallbackToLastKnownValidPartialsForValidationWhenConfigSaveWithLastKnownPartialsWithMainConfigFails() {
String pipelineOneFromConfigRepo = "pipeline_one_from_config_repo";
String invalidPartial = "invalidPartial";
final String pipelineInMain = "pipeline_in_main";
PartialConfig validPartialConfig = PartialConfigMother.withPipeline(pipelineOneFromConfigRepo, new RepoConfigOrigin(repoConfig, "1"));
PartialConfig invalidPartialConfig = PartialConfigMother.invalidPartial(invalidPartial, new RepoConfigOrigin(repoConfig, "2"));
cachedGoPartials.addOrUpdate(repoConfig.getMaterialConfig().getFingerprint(), validPartialConfig);
cachedGoPartials.markAllKnownAsValid();
cachedGoPartials.addOrUpdate(repoConfig.getMaterialConfig().getFingerprint(), invalidPartialConfig);
GoFileConfigDataSource.GoConfigSaveResult result = dataSource.writeWithLock(new UpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
cruiseConfig.addPipeline("default", PipelineConfigMother.createPipelineConfig(pipelineInMain, "stage", "job"));
return cruiseConfig;
}
}, new GoConfigHolder(configHelper.currentConfig(), configHelper.currentConfig()));
assertThat(result.getConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(invalidPartial)), is(false));
assertThat(result.getConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(pipelineOneFromConfigRepo)), is(true));
assertThat(result.getConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(pipelineInMain)), is(true));
assertThat(cachedGoPartials.lastValidPartials().size(), is(1));
PartialConfig partialConfig = cachedGoPartials.lastValidPartials().get(0);
assertThat(partialConfig.getGroups(), is(validPartialConfig.getGroups()));
assertThat(partialConfig.getEnvironments(), is(validPartialConfig.getEnvironments()));
assertThat(partialConfig.getOrigin(), is(validPartialConfig.getOrigin()));
}
use of com.thoughtworks.go.config.remote.PartialConfig in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldNotSaveConfigIfValidationOfLastKnownValidPartialsMergedWithMainConfigFails.
@Test
public void shouldNotSaveConfigIfValidationOfLastKnownValidPartialsMergedWithMainConfigFails() {
final PipelineConfig upstream = PipelineConfigMother.createPipelineConfig(UUID.randomUUID().toString(), "s1", "j1");
configHelper.addPipeline(upstream);
String remotePipeline = "remote_pipeline";
RepoConfigOrigin repoConfigOrigin = new RepoConfigOrigin(this.repoConfig, "1");
PartialConfig partialConfig = PartialConfigMother.pipelineWithDependencyMaterial(remotePipeline, upstream, repoConfigOrigin);
cachedGoPartials.addOrUpdate(this.repoConfig.getMaterialConfig().getFingerprint(), partialConfig);
cachedGoPartials.markAllKnownAsValid();
thrown.expect(RuntimeException.class);
thrown.expectCause(any(GoConfigInvalidException.class));
thrown.expectMessage(String.format("Stage with name 's1' does not exist on pipeline '%s', it is being referred to from pipeline '%s' (%s)", upstream.name(), remotePipeline, repoConfigOrigin.displayName()));
dataSource.writeWithLock(new UpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
PipelineConfig pipelineConfig = cruiseConfig.getPipelineConfigByName(upstream.name());
pipelineConfig.clear();
pipelineConfig.add(new StageConfig(new CaseInsensitiveString("new_stage"), new JobConfigs(new JobConfig("job"))));
return cruiseConfig;
}
}, new GoConfigHolder(configHelper.currentConfig(), configHelper.currentConfig()));
}
Aggregations