Skip to content

Commit

Permalink
Merge pull request #132 from gsheasby/fix/allow-additional-environmen…
Browse files Browse the repository at this point in the history
…t-to-override-system

LocalBuilder: Allow additionalEnvironment to override systemEnvironment
  • Loading branch information
iamdanfox authored Nov 22, 2016
2 parents f847f20 + 0356ee7 commit de73c23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ public LocalBuilder withEnvironment(Map<String, String> newEnvironment) {
public DockerMachine build() {
dockerType.validateEnvironmentVariables(systemEnvironment);
AdditionalEnvironmentValidator.validate(additionalEnvironment);
Map<String, String> environment = ImmutableMap.<String, String>builder()
.putAll(systemEnvironment)
.putAll(additionalEnvironment)
.build();
Map<String, String> combinedEnvironment = newHashMap();
combinedEnvironment.putAll(systemEnvironment);
combinedEnvironment.putAll(additionalEnvironment);

String dockerHost = systemEnvironment.getOrDefault(DOCKER_HOST, "");
return new DockerMachine(dockerType.resolveIp(dockerHost), environment);
return new DockerMachine(dockerType.resolveIp(dockerHost), ImmutableMap.copyOf(combinedEnvironment));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ public void get_variable_overriden_with_additional_environment() throws Exceptio
assertThat(localMachine, containsEnvironment(expected));
}

@Test
public void override_system_environment_with_additional_environment() throws Exception {
Map<String, String> systemEnv = ImmutableMap.<String, String>builder()
.put("ENV_1", "VAL_1")
.build();
Map<String, String> overrideEnv = ImmutableMap.<String, String>builder()
.put("ENV_1", "DIFFERENT_VALUE")
.build();
DockerMachine localMachine = new LocalBuilder(DAEMON, systemEnv)
.withEnvironment(overrideEnv)
.build();

assertThat(localMachine, not(containsEnvironment(systemEnv)));
assertThat(localMachine, containsEnvironment(overrideEnv));
}

@Test
public void have_invalid_variables_daemon() throws Exception {
Map<String, String> invalidDockerVariables = ImmutableMap.<String, String>builder()
Expand Down

0 comments on commit de73c23

Please sign in to comment.