use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class DefaultSchedulingContextTest method shouldCreatePermittedAgentContextCorrectly.
@Test
public void shouldCreatePermittedAgentContextCorrectly() throws Exception {
AgentConfig linux = agent("uuid1", "linux");
AgentConfig windows = agent("uuid2", "windows");
windows.disable();
Agents matchingAgents = new Agents(linux, windows);
EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig();
existing.add("firstVar", "firstVal");
existing.add("overriddenVar", "originalVal");
SchedulingContext schedulingContext = new DefaultSchedulingContext("approver", matchingAgents);
schedulingContext = schedulingContext.overrideEnvironmentVariables(existing);
EnvironmentVariablesConfig stageLevel = new EnvironmentVariablesConfig();
stageLevel.add("stageVar", "stageVal");
stageLevel.add("overriddenVar", "overriddenVal");
StageConfig config = StageConfigMother.custom("test", Approval.automaticApproval());
config.setVariables(stageLevel);
SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables());
ReflectionUtil.setField(context, "rerun", true);
SchedulingContext permittedAgentContext = context.permittedAgent("uuid1");
Agents agents = (Agents) ReflectionUtil.getField(permittedAgentContext, "agents");
assertThat(agents.size(), is(1));
assertThat(agents.get(0).getAgentIdentifier().getUuid(), is("uuid1"));
assertThat(permittedAgentContext.isRerun(), is(true));
assertThat(permittedAgentContext.getApprovedBy(), is("approver"));
EnvironmentVariablesConfig environmentVariablesUsed = permittedAgentContext.getEnvironmentVariablesConfig();
assertThat(environmentVariablesUsed.size(), is(3));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("firstVar", "firstVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("overriddenVar", "overriddenVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("stageVar", "stageVal")));
}
use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class DefaultSchedulingContextTest method shouldCreateRerunSchedulingContextCorrectly.
@Test
public void shouldCreateRerunSchedulingContextCorrectly() throws Exception {
AgentConfig linux = agent("uuid1", "linux");
AgentConfig windows = agent("uuid2", "windows");
windows.disable();
Agents matchingAgents = new Agents(linux, windows);
EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig();
existing.add("firstVar", "firstVal");
existing.add("overriddenVar", "originalVal");
SchedulingContext schedulingContext = new DefaultSchedulingContext("approver", matchingAgents);
schedulingContext = schedulingContext.overrideEnvironmentVariables(existing);
EnvironmentVariablesConfig stageLevel = new EnvironmentVariablesConfig();
stageLevel.add("stageVar", "stageVal");
stageLevel.add("overriddenVar", "overriddenVal");
StageConfig config = StageConfigMother.custom("test", Approval.automaticApproval());
config.setVariables(stageLevel);
SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables());
SchedulingContext rerunContext = context.rerunContext();
assertThat(rerunContext.isRerun(), is(true));
assertThat(rerunContext.getApprovedBy(), is("approver"));
Agents agents = (Agents) ReflectionUtil.getField(rerunContext, "agents");
assertThat(agents, is(matchingAgents));
EnvironmentVariablesConfig environmentVariablesUsed = rerunContext.getEnvironmentVariablesConfig();
assertThat(environmentVariablesUsed.size(), is(3));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("firstVar", "firstVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("overriddenVar", "overriddenVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("stageVar", "stageVal")));
}
use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class MyGoController method getStagesModelsFor.
private List<PipelineViewModel.StageViewModel> getStagesModelsFor(PipelineConfig pipelineConfig) {
List<PipelineViewModel.StageViewModel> stageModels = new ArrayList<>();
stageModels.add(new PipelineViewModel.StageViewModel(GoConstants.ANY_STAGE));
for (StageConfig stageConfig : pipelineConfig) {
stageModels.add(new PipelineViewModel.StageViewModel(CaseInsensitiveString.str(stageConfig.name())));
}
return stageModels;
}
use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class PipelineScheduleServiceTest method setup.
@Before
public void setup() throws Exception {
configHelper = new GoConfigFileHelper();
configHelper.usingCruiseConfigDao(goConfigDao);
configHelper.onSetUp();
testRepo = new SvnTestRepo("testSvnRepo");
dbHelper.onSetUp();
repository = new SvnCommand(null, testRepo.projectRepositoryUrl());
mingleConfig = configHelper.addPipeline("mingle", STAGE_NAME, repository, "unit", "functional");
goConfig = configHelper.addPipeline("go", STAGE_NAME, repository, "unit");
StageConfig ftStageConfig = StageConfigMother.custom("ft", "twist");
ftStageConfig.jobConfigByConfigName(new CaseInsensitiveString("twist")).addVariable("JOB_LVL", "job value");
ftStageConfig.setVariables(env("STAGE_LVL", "stage value"));
configHelper.addStageToPipeline("go", ftStageConfig);
configHelper.addEnvironmentVariableToPipeline("go", env("PIPELINE_LVL", "pipeline value"));
configHelper.addEnvironments("uat");
EnvironmentConfig uatEnv = configHelper.currentConfig().getEnvironments().named(new CaseInsensitiveString("uat"));
uatEnv.addPipeline(new CaseInsensitiveString("go"));
uatEnv.addEnvironmentVariable("ENV_LVL", "env value");
evolveConfig = configHelper.addPipeline("evolve", STAGE_NAME, repository, "unit");
goCache.clear();
}
use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class StageInfoAdapterTest method shouldReturnCorrectAutoApprovedStatus.
@Test
public void shouldReturnCorrectAutoApprovedStatus() throws Exception {
StageConfig stage = StageConfigMother.custom("dev", new JobConfigs());
assertThat(stage.requiresApproval(), is(false));
assertThat(new StageInfoAdapter(stage).isAutoApproved(), is(true));
}
Aggregations