Skip to content

Commit

Permalink
update code as suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Apr 11, 2024
1 parent a73ba2f commit 08787b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions java/src/org/openqa/selenium/docker/ContainerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -53,7 +52,15 @@ public ContainerConfig(
List<Device> devices,
String networkName,
long shmSize) {
this(image, portBindings, envVars, volumeBinds, devices, networkName, shmSize, new HashMap<>());
this(
image,
portBindings,
envVars,
volumeBinds,
devices,
networkName,
shmSize,
ImmutableMap.of());
}

public ContainerConfig(
Expand All @@ -73,7 +80,7 @@ public ContainerConfig(
this.networkName = networkName;
this.autoRemove = true;
this.shmSize = shmSize;
this.hostConfig = hostConfig;
this.hostConfig = hostConfig != null ? hostConfig : ImmutableMap.of();
}

public static ContainerConfig image(Image image) {
Expand Down Expand Up @@ -138,7 +145,7 @@ public ContainerConfig devices(List<Device> devices) {
image, portBindings, envVars, volumeBinds, devices, networkName, shmSize);
}

public ContainerConfig getHostConfig(Map<String, Object> hostConfig, List<String> configKeys) {
public ContainerConfig applyHostConfig(Map<String, Object> hostConfig, List<String> configKeys) {
Map<String, Object> setHostConfig =
configKeys.stream()
.filter(hostConfig::containsKey)
Expand Down Expand Up @@ -204,9 +211,7 @@ private Map<String, Object> toJson() {
"Devices", devicesMapping);

if (this.hostConfig != null && !this.hostConfig.isEmpty()) {
Map<String, Object> copyMap = new HashMap<>(hostConfig);
copyMap.putAll(this.hostConfig);
hostConfig = ImmutableMap.copyOf(copyMap);
hostConfig = ImmutableMap.copyOf(this.hostConfig);
}

return ImmutableMap.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private Container createBrowserContainer(
.shmMemorySize(browserContainerShmMemorySize)
.network(networkName)
.devices(devices)
.getHostConfig(hostConfig, hostConfigKeys);
.applyHostConfig(hostConfig, hostConfigKeys);
if (!runningInDocker) {
containerConfig = containerConfig.map(Port.tcp(4444), Port.tcp(port));
}
Expand Down

0 comments on commit 08787b9

Please sign in to comment.