use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class GoConfigServiceTest method shouldNotAllowEditOfConfigRepoPipelines.
@Test
public void shouldNotAllowEditOfConfigRepoPipelines() throws Exception {
CruiseConfig cruiseConfig = mock(CruiseConfig.class);
when(goConfigDao.load()).thenReturn(cruiseConfig);
PipelineConfig pipeline = new PipelineConfig();
pipeline.setName("pipeline1");
pipeline.setOrigin(new RepoConfigOrigin());
when(cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1"))).thenReturn(pipeline);
when(cruiseConfig.getGroups()).thenReturn(new GoConfigMother().cruiseConfigWithOnePipelineGroup().getGroups());
when(cruiseConfig.isAdministrator("admin_user")).thenReturn(true);
assertFalse(goConfigService.canEditPipeline("pipeline1", new Username("admin_user")));
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class PipelineConfigServiceTest method setUp.
@Before
public void setUp() throws Exception {
PipelineConfigs configs = createGroup("group", "pipeline", "in_env");
downstream(configs);
cruiseConfig = new BasicCruiseConfig(configs);
cruiseConfig.addEnvironment(environment("foo", "in_env"));
PipelineConfig remotePipeline = PipelineConfigMother.pipelineConfig("remote");
remotePipeline.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(new GitMaterialConfig("url"), "plugin"), "1234"));
cruiseConfig.addPipeline("group", remotePipeline);
goConfigService = mock(GoConfigService.class);
securityService = mock(SecurityService.class);
pluggableTaskService = mock(PluggableTaskService.class);
when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
when(goConfigService.cruiseConfig()).thenReturn(cruiseConfig);
when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
when(goConfigService.getMergedConfigForEditing()).thenReturn(cruiseConfig);
when(goConfigService.getAllPipelineConfigs()).thenReturn(cruiseConfig.getAllPipelineConfigs());
pipelineConfigService = new PipelineConfigService(goConfigService, securityService, pluggableTaskService, null);
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class BuildCauseProducerServiceTest method manualTrigger_shouldUpdateJustPipelineConfigNotMaterialsWhenPipelineIsDefinedInConfigRepoAndMDUFlagIsTurnedOff.
@Test
public void manualTrigger_shouldUpdateJustPipelineConfigNotMaterialsWhenPipelineIsDefinedInConfigRepoAndMDUFlagIsTurnedOff() {
HgMaterial material1 = new HgMaterial("url", null);
HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
pipelineConfig.addMaterialConfig(materialConfig1);
pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig2, "plug"), "revision1"));
when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
when(materialConfigConverter.toMaterial(materialConfig2)).thenReturn(new MaterialConfigConverter().toMaterial(materialConfig2));
ScheduleOptions scheduleOptions = new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>());
scheduleOptions.shouldPerformMDUBeforeScheduling(false);
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), scheduleOptions, new ServerHealthStateOperationResult());
verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
verify(mockMaterialUpdateStatusNotifier).registerListenerFor(eq(pipelineConfig), any(MaterialUpdateStatusListener.class));
verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.
the class CachedGoPartialsTest method setUp.
@Before
public void setUp() throws Exception {
serverHealthService = new ServerHealthService();
partials = new CachedGoPartials(serverHealthService);
configRepo1 = new ConfigRepoConfig(new GitMaterialConfig("url1"), "plugin");
part1 = PartialConfigMother.withPipeline("p1", new RepoConfigOrigin(configRepo1, "1"));
configRepo2 = new ConfigRepoConfig(new GitMaterialConfig("url2"), "plugin");
part2 = PartialConfigMother.withPipeline("p2", new RepoConfigOrigin(configRepo2, "1"));
partials.addOrUpdate(configRepo1.getMaterialConfig().getFingerprint(), part1);
partials.addOrUpdate(configRepo2.getMaterialConfig().getFingerprint(), part2);
fingerprintForRepo1 = ((RepoConfigOrigin) part1.getOrigin()).getMaterial().getFingerprint();
fingerprintForRepo2 = ((RepoConfigOrigin) part2.getOrigin()).getMaterial().getFingerprint();
}
use of com.thoughtworks.go.config.remote.RepoConfigOrigin 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()));
}
Aggregations