use of org.apache.mesos.v1.Protos.Environment in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testEnvironmentVariableOverrides.
@Test
public void testEnvironmentVariableOverrides() {
Map<String, String> overrideVariables = new HashMap<>();
overrideVariables.put("MY_NEW_ENV_VAR", "test");
overrideVariables.put("STARTED_BY_USER", "notTestUser");
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setCommand(Optional.of("/bin/echo hi")).build();
final SingularityPendingTask pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(new SingularityPendingTaskId("test", "1", 0, 1, PendingType.IMMEDIATE, 0)).setUser(user).setEnvOverrides(overrideVariables).build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final TaskInfo task = builder.buildTask(offerHolder, null, taskRequest, taskResources, executorResources).getMesosTask();
Map<String, String> environmentVariables = task.getCommand().getEnvironment().getVariablesList().stream().collect(Collectors.toMap(Variable::getName, Variable::getValue));
for (String key : overrideVariables.keySet()) {
assertEquals("Environment variable " + key + " not overridden.", environmentVariables.get(key), overrideVariables.get(key));
}
}
Aggregations