ExecutorModule extends AbstractModule { @VisibleForTesting static CommandInfo makeExecutorCommand( String thermosExecutorPath, List<String> thermosExecutorResources, boolean thermosHomeInSandbox, String thermosExecutorFlags) { Stream<String> resourcesToFetch = Stream.concat( ImmutableList.of(thermosExecutorPath).stream(), thermosExecutorResources.stream()); StringBuilder sb = new StringBuilder(); if (thermosHomeInSandbox) { sb.append("HOME=${MESOS_SANDBOX=.} "); } sb.append("${MESOS_SANDBOX=.}/"); sb.append(uriBasename(thermosExecutorPath)); sb.append(" "); sb.append(Optional.ofNullable(thermosExecutorFlags).orElse("")); return CommandInfo.newBuilder() .setValue(sb.toString().trim()) .addAllUris(resourcesToFetch .map(r -> URI.newBuilder().setValue(r).setExecutable(true).build()) .collect(GuavaUtils.toImmutableList())) .build(); }    }
@Test public void testMakeExecutorCommand() { testSingleCommand( "/path/executor.pex", ImmutableList.of(), false, null, "${MESOS_SANDBOX=.}/executor.pex", ImmutableList.of("/path/executor.pex")); testSingleCommand( "/path/executor.pex", ImmutableList.of(), true, null, "HOME=${MESOS_SANDBOX=.} ${MESOS_SANDBOX=.}/executor.pex", ImmutableList.of("/path/executor.pex")); testSingleCommand( "/path/executor.pex", ImmutableList.of("/other/thing.pex"), false, null, "${MESOS_SANDBOX=.}/executor.pex", ImmutableList.of("/path/executor.pex", "/other/thing.pex")); testSingleCommand( "/path/executor.pex", ImmutableList.of(), false, "--extra=args", "${MESOS_SANDBOX=.}/executor.pex --extra=args", ImmutableList.of("/path/executor.pex")); }