Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
195d9af
Locate docker and docker-compose using the path variable.
Mar 1, 2017
ab078a6
Merge branch 'feature/use-path-to-find-executables' of https://github…
hpryce Mar 7, 2017
a12076d
Reintroduce support for explicitly setting docker-compose location.
hpryce Mar 7, 2017
35ab870
Docker for Mac is not in the path when tests run from IDE.
hpryce Mar 7, 2017
252a88e
Split out finding possible command locations from testing those locat…
hpryce Mar 7, 2017
0a61921
Add jsr dep
hpryce Mar 7, 2017
d39fb31
Refactor to simply logic and improve test coverage by using Environme…
hpryce Mar 8, 2017
19791dd
Add case for Windows path variable "Path"
hpryce Mar 8, 2017
a734f16
Process builder will look for command on the path
hpryce Mar 8, 2017
215f427
Move integ tests into separate source set.
hpryce Mar 8, 2017
a8ce98b
Add very simple windows smoke test.
hpryce Mar 8, 2017
cc06e21
Wire up smoke test for Windows to appveyor.
hpryce Mar 9, 2017
186aba0
Thread.sleep isn't accurate on Windows
hpryce Mar 9, 2017
ed0d9cf
Simply don't run the tes that relies upon Thread.sleep on Windows
hpryce Mar 9, 2017
17a0b3b
Merge branch 'feature/look_in_path' into feature/windows_smoke_tests
hpryce Mar 9, 2017
bc6bdd9
Do we have the latest image?
hpryce Mar 10, 2017
1df8a38
Use Windows Server 2016 image
hpryce Mar 10, 2017
e903dac
Install docker-compose before running tests that need it
hpryce Mar 10, 2017
8c41711
Use image with more up to date docker
hpryce Mar 10, 2017
479efca
Correct appveyor.yml syntax
hpryce Mar 10, 2017
9492fb4
Try cinst
hpryce Mar 10, 2017
eafa3b0
Try installing both docker and docker-compose on old image
hpryce Mar 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Process builder will look for command on the path
  • Loading branch information
hpryce committed Mar 8, 2017
commit a734f16a6036699312d9b743e3f9fb55e9ffcf24

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
package com.palantir.docker.compose.execution;

import static java.util.Collections.singletonList;

import com.google.common.collect.ImmutableList;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -28,13 +27,20 @@
@Value.Immutable
public abstract class DockerCommandLocator {

private static final List<String> MAC_SEARCH_LOCATIONS = ImmutableList.of("/usr/local/bin", "/usr/bin");

protected abstract String command();

@Value.Default
protected boolean isWindows() {
return SystemUtils.IS_OS_WINDOWS;
}

@Value.Default
protected List<String> macSearchLocations() {
return MAC_SEARCH_LOCATIONS;
}

@Value.Derived
protected String executableName() {
if (isWindows()) {
Expand All @@ -46,22 +52,17 @@ protected String executableName() {
@Nullable
protected abstract String locationOverride();

@Value.Derived
protected List<Path> searchLocations() {
if (locationOverride() == null) {
return DockerCommandLocations.pathLocations();
}
return singletonList(Paths.get(locationOverride()));
}

public String getLocation() {
return searchLocations()
if (locationOverride() != null) {
return locationOverride();
}
return macSearchLocations()
.stream()
.map(p -> p.resolve(executableName()))
.map(p -> Paths.get(p, executableName()))
.filter(Files::exists)
.findFirst()
.map(Path::toString)
.orElseThrow(() -> new IllegalStateException("Could not find " + command() + " in " + searchLocations()));
.orElse(executableName());
}

public static ImmutableDockerCommandLocator.Builder forCommand(String command) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ public Process execute(String... commands) throws IOException {
public static ImmutableDockerExecutable.Builder builder() {
return ImmutableDockerExecutable.builder();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
*/
package com.palantir.docker.compose.execution;

import static java.util.Collections.singletonList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;

Expand All @@ -36,63 +35,48 @@ public class DockerCommandLocatorShould {

@Rule public ExpectedException exception = ExpectedException.none();

@Rule public EnvironmentVariables environmentVariables = new EnvironmentVariables();

private Path firstPathFolder;

private String commandFileLocation;
private String windowsCommandFileLocation;

@Before
public void setup() throws IOException {
firstPathFolder = folder.newFolder("first").toPath();

commandFileLocation = Files.createFile(firstPathFolder.resolve(command)).toString();
windowsCommandFileLocation = Files.createFile(firstPathFolder.resolve(windowsCommand)).toString();

environmentVariables.set("PATH", firstPathFolder.toString());
}

@Test public void
provide_the_first_command_location() {
returns_the_command_name_when_no_other_paths_contain_command() {
DockerCommandLocator locator = DockerCommandLocator.forCommand(command)
.isWindows(false)
.build();
assertThat(locator.getLocation(), is(commandFileLocation));

assertThat(locator.getLocation(), is(command));
}

@Test public void
provide_the_first_command_location_on_windows() {
returns_the_command_name_with_exe_on_windows_when_no_other_paths_contain_command() {
DockerCommandLocator locator = DockerCommandLocator.forCommand(command)
.isWindows(true)
.build();
assertThat(locator.getLocation(), is(windowsCommandFileLocation));

assertThat(locator.getLocation(), is(windowsCommand));
}

@Test public void
fail_when_no_paths_contain_command() {
environmentVariables.set("PATH", null);
allow_the_path_to_be_overriden() throws IOException {
Path overrideFolder = folder.newFolder("override").toPath();
String overridenCommand = Files.createFile(overrideFolder.resolve(command)).toString();

DockerCommandLocator locator = DockerCommandLocator.forCommand(command)
.locationOverride(overridenCommand)
.isWindows(false)
.build();

exception.expect(IllegalStateException.class);
exception.expectMessage("Could not find " + command + " in [/usr/local/bin, /usr/bin]");
locator.getLocation();
assertThat(locator.getLocation(), is(overridenCommand));
}

@Test public void
allow_the_path_to_be_overriden() throws IOException {
Path overrideFolder = folder.newFolder("override").toPath();
String overridenCommand = Files.createFile(overrideFolder.resolve(command)).toString();
search_in_known_mac_install_locations_for_the_command() throws IOException {
Path macSearchFolder = folder.newFolder("override").toPath();
String commandLocation = Files.createFile(macSearchFolder.resolve(command)).toString();

DockerCommandLocator locator = DockerCommandLocator.forCommand(command)
.locationOverride(overrideFolder.toString())
.macSearchLocations(singletonList(macSearchFolder.toString()))
.isWindows(false)
.build();

assertThat(locator.getLocation(), is(overridenCommand));
assertThat(locator.getLocation(), is(commandLocation));
}

}