Skip to content

Commit

Permalink
[fabric8io#1528] determineFinalArgValue respect default value if key …
Browse files Browse the repository at this point in the history
…exists but value is null
  • Loading branch information
twendelmuth committed Feb 23, 2022
1 parent 5f71139 commit 04f7918
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private static void updateMapWithArgValue(Map<String, String> result, Map<String

private static String determineFinalArgValue(String argString, String[] argStringParts, Map<String, String> args) {
String argStringValue = argString.substring(argStringParts[0].length() + 1);
if(args == null){
if(args == null || args.get(argStringParts[0]) == null){
return argStringValue;
}
return args.getOrDefault(argStringParts[0], argStringValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public void testExtractArgsFromDockerfile() {
assertEquals("{busyboxVersion=latest}", DockerFileUtil.extractArgsFromLines(Collections.singletonList(new String[]{"ARG", "busyboxVersion=latest"}), null).toString());
}

@Test
public void testExtractArgsFromDockerFile_parameterMapWithNullValues() {
assertEquals("{VERSION=latest, FULL_IMAGE=busybox:latest}", DockerFileUtil.extractArgsFromLines(Arrays.asList(new String[]{"ARG", "VERSION:latest"}, new String[] {"ARG", "FULL_IMAGE=busybox:latest"}), Collections.singletonMap("VERSION", null)).toString());
assertEquals("{VERSION=latest, FULL_IMAGE=busybox:latest}", DockerFileUtil.extractArgsFromLines(Arrays.asList(new String[]{"ARG", "VERSION=latest"}, new String[] {"ARG", "FULL_IMAGE=busybox:latest"}), Collections.singletonMap("VERSION", null)).toString());
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidArgWithSpacesFromDockerfile() {
DockerFileUtil.extractArgsFromLines(Collections.singletonList(new String[]{"ARG", "MY_IMAGE image with spaces"}), Collections.emptyMap());
Expand Down

0 comments on commit 04f7918

Please sign in to comment.