use of com.thoughtworks.go.config.Agents 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.Agents in project gocd by gocd.
the class DefaultSchedulingContextTest method shouldNotMatchDeniedAgents.
@Test
public void shouldNotMatchDeniedAgents() throws Exception {
AgentConfig linux = agent("uuid1", "linux");
AgentConfig windows = agent("uuid2", "windows");
windows.disable();
Agents matchingAgents = new Agents(linux, windows);
DefaultSchedulingContext context = new DefaultSchedulingContext("approved", matchingAgents);
assertThat(context.findAgentsMatching(resources()), is(new Agents(linux)));
}
use of com.thoughtworks.go.config.Agents in project gocd by gocd.
the class DefaultSchedulingContextTest method shouldFindNoAgentsIfNoneExist.
@Test
public void shouldFindNoAgentsIfNoneExist() throws Exception {
DefaultSchedulingContext context = new DefaultSchedulingContext("approved", new Agents());
assertThat(context.findAgentsMatching(new Resources()), is(new Agents()));
}
use of com.thoughtworks.go.config.Agents in project gocd by gocd.
the class DefaultSchedulingContextTest method shouldFindAllAgentsIfNoResourcesAreSpecified.
@Test
public void shouldFindAllAgentsIfNoResourcesAreSpecified() throws Exception {
AgentConfig linux = agent("uuid1", "linux");
AgentConfig windows = agent("uuid2", "windows");
Agents matchingAgents = new Agents(linux, windows);
DefaultSchedulingContext context = new DefaultSchedulingContext("approved", matchingAgents);
assertThat(context.findAgentsMatching(new Resources()), is(matchingAgents));
}
use of com.thoughtworks.go.config.Agents 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")));
}
Aggregations