@Test public void shouldReturnFalseForPipelineThatNotInFirstGroup_WhenSecondGroupIsRemote() { PipelineConfigs group1 = createGroup("group1", createPipelineConfig("pipeline1", "stage1")); CruiseConfig config = new BasicCruiseConfig(new BasicCruiseConfig(group1), PartialConfigMother.withPipelineInGroup("remote-pipe-1", "remote_group")); assertThat("shouldReturnFalseForPipelineThatNotInFirstGroup", config.isInFirstGroup(new CaseInsensitiveString("pipeline2")), is(false)); }
@Test public void shouldValidateIfNameIsMissing() { SCM scm = new SCM(); scm.validate(new ConfigSaveValidationContext(new BasicCruiseConfig(), null)); assertThat(scm.errors().getAllOn(SCM.NAME), is(asList("Please provide name"))); }
@Test public void shouldReturnFalseWhenHasNotPipelinesFrom2Parts() { pipelines = new BasicPipelineConfigs("group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1")); BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines); cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2")); assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(false)); }
@Test public void shouldReturnTrueHasPipelinesFrom2Parts() { pipelines = new BasicPipelineConfigs("group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1")); BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines); cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2")); assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe1")), is(true)); assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe2")), is(true)); }
@Test public void shouldNotThrowAnExceptionWhenAPipelineHasAtLeastOneStage() throws Exception { PipelineConfig pipelineConfig = pipelineConfigWithGivenStages("foo"); preprocessor.process(new BasicCruiseConfig(new BasicPipelineConfigs(pipelineConfig))); }
@Test public void shouldNotAllowParamsInsideResourceNameWhenOutsideTemplates() throws Exception { ResourceConfig resourceConfig = resource("#{PARAMS}"); ValidationContext context = ConfigSaveValidationContext.forChain(new BasicCruiseConfig(), new PipelineConfig()); resourceConfig.validate(context); assertThat(resourceConfig.errors().isEmpty(), is(false)); assertThat(resourceConfig.errors().on(JobConfig.RESOURCES), is(String.format("Resource name '#{PARAMS}' is not valid. Valid names much match '%s'", ResourceConfig.VALID_REGEX))); }
@Test public void shouldgetAllPipelineNamesFromAllParts() { pipelines = new BasicPipelineConfigs("group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1")); BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines); cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipelineInGroup("pipe2", "g2"), PartialConfigMother.withPipelineInGroup("pipe3", "g3")); assertThat(cruiseConfig.getAllPipelineNames(), contains( new CaseInsensitiveString("pipe1"), new CaseInsensitiveString("pipe2"), new CaseInsensitiveString("pipe3"))); }
@Test public void shouldModifyEmptyEnvironmentConfigWithUIOrigin() { BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines); PartialConfig partialConfig = PartialConfigMother.withEnvironment("remoteEnv"); partialConfig.setOrigins(new RepoConfigOrigin()); cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, true, partialConfig); cruiseConfig.getEnvironments().get(0).addAgent("agent"); MergeEnvironmentConfig mergedEnv = (MergeEnvironmentConfig) cruiseConfig.getEnvironments().get(0); assertThat(mergedEnv.getFirstEditablePart().getAgents(), hasItem(new EnvironmentAgentConfig("agent"))); }
@Test public void shouldValidateAgainstSettingRunOnAllAgentsAndRunInstanceCountSetTogether() { JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("test")); jobConfig.setRunOnAllAgents(true); jobConfig.setRunInstanceCount(10); jobConfig.validate(ConfigSaveValidationContext.forChain(new BasicCruiseConfig())); ConfigErrors configErrors = jobConfig.errors(); assertThat(configErrors.isEmpty(), is(false)); assertThat(configErrors.on(JobConfig.RUN_TYPE), is("Job cannot be 'run on all agents' type and 'run multiple instance' type together.")); }
@Test public void shouldValidateAgainstSettingRunOnAllAgentsForAJobAssignedToElasticAgent() { JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("test")); jobConfig.setRunOnAllAgents(true); jobConfig.setElasticProfileId("ubuntu-dev"); jobConfig.validate(ConfigSaveValidationContext.forChain(new BasicCruiseConfig())); ConfigErrors configErrors = jobConfig.errors(); assertThat(configErrors.isEmpty(), is(false)); assertThat(configErrors.on(JobConfig.RUN_TYPE), is("Job cannot be set to 'run on all agents' when assigned to an elastic agent")); }
public static CruiseConfig configWithConfigRepo() { CruiseConfig cruiseConfig = new BasicCruiseConfig(); cruiseConfig.setConfigRepos(new ConfigReposConfig(new ConfigRepoConfig( new GitMaterialConfig("https://github.com/tomzo/gocd-indep-config-part.git"), "myplugin", "id2" ))); return cruiseConfig; }
@Test public void shouldBeValid() throws Exception { ExecTask execTask = new ExecTask("", new Arguments(new Argument("arg1"), new Argument("arg2"))); execTask.validate(ConfigSaveValidationContext.forChain(new BasicCruiseConfig())); assertThat(execTask.errors().isEmpty(), is(true)); execTask = new ExecTask("command", "", "blah"); execTask.validate(ConfigSaveValidationContext.forChain(new BasicCruiseConfig())); assertThat(execTask.errors().isEmpty(), is(true)); }
@Test public void uniqueMaterialForAutoPipelinesShouldNotReturnPackageMaterialsWithAutoUpdateFalse() throws Exception { PipelineConfig pipeline1 = pipelineWithManyMaterials(false); pipeline1.add(new StageConfig(new CaseInsensitiveString("manual-stage"), new JobConfigs(), new Approval())); CruiseConfig config = new BasicCruiseConfig(new BasicPipelineConfigs(pipeline1)); assertThat(config.getAllUniqueMaterialsBelongingToAutoPipelines().size(), is(3)); }
@Test public void shouldRemoveErrorLogWhenCorrespondingPipelineIsMissing() throws Exception { serverHealthService.update(ServerHealthState.error("message", "description", pipelineId)); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forPipeline("other")))); serverHealthService.purgeStaleHealthMessages(new BasicCruiseConfig()); assertThat(serverHealthService.logs().size(), is(0)); }
@Test public void shouldThrowExceptionIfRoleNameInPipelinesAuthorizationDoesNotExist_ConfigSaveValidationContext() { AdminRole role = new AdminRole(new CaseInsensitiveString("role2")); PipelineConfigs pipelinesConfig = new BasicPipelineConfigs(new Authorization(new ViewConfig(role))); CruiseConfig config = new BasicCruiseConfig(pipelinesConfig); role.validate(ConfigSaveValidationContext.forChain(config)); ConfigErrors errors = role.errors(); assertThat(errors.isEmpty(), is(false)); assertThat(errors.on(AdminRole.NAME), is("Role \"role2\" does not exist.")); }
@Test public void shouldFailValidateWhenUpstreamPipelineForDependencyMaterialDoesNotExist() { String upstreamPipeline = "non-existant"; PipelineConfig pipelineConfig = GoConfigMother.createPipelineConfigWithMaterialConfig( new DependencyMaterialConfig(new CaseInsensitiveString(upstreamPipeline), new CaseInsensitiveString("non-existant"))); BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(pipelineConfig)); boolean isValid = pipelineConfig.validateTree(PipelineConfigSaveValidationContext.forChain(true, cruiseConfig.getGroups().first().getGroup(), cruiseConfig, pipelineConfig)); assertThat(isValid, is(false)); ConfigErrors materialErrors = pipelineConfig.materialConfigs().first().errors(); assertThat(materialErrors.isEmpty(), is(false)); assertThat(materialErrors.firstError(), is("Pipeline with name 'non-existant' does not exist, it is defined as a dependency for pipeline 'pipeline' (cruise-config.xml)")); }
@Test public void shouldNotIncludePackageMaterialsWithAutoUpdateFalse() { PipelineConfig pipeline1 = pipelineWithManyMaterials(false); pipeline1.addMaterialConfig(getPackageMaterialConfigWithAutoUpdateFalse()); pipeline1.addMaterialConfig(getPackageMaterialConfigWithAutoUpdateTrue()); pipeline1.add(new StageConfig(new CaseInsensitiveString("manual-stage"), new JobConfigs(), new Approval())); CruiseConfig config = new BasicCruiseConfig(new BasicPipelineConfigs(pipeline1)); assertThat(config.getAllUniqueMaterialsBelongingToAutoPipelines().size(), is(4)); }
@Test public void shouldValidateAPipelineHasAtleastOneStage() { PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("p"), new MaterialConfigs()); pipelineConfig.validateTree(PipelineConfigSaveValidationContext.forChain(true, "group", new BasicCruiseConfig(new BasicPipelineConfigs("group", new Authorization())), pipelineConfig)); assertThat(pipelineConfig.errors().on("pipeline"), is("Pipeline 'p' does not have any stages configured. A pipeline must have at least one stage.")); }
@Test public void globalStateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.invalidConfig())); assertTrue((serverHealthService.logs().get(0)).getPipelineNames(config).isEmpty()); }
@Test public void faninErrorStateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(HealthStateScope.forFanin("pipeline2")))); Set<String> pipelines = (serverHealthService.logs().get(0)).getPipelineNames(config); assertEquals(Sets.newHashSet("pipeline2"), pipelines); } }