From 2ec9032199d37713fea0a8fd7f1ca5fa18d344cd Mon Sep 17 00:00:00 2001 From: munishchouhan Date: Mon, 18 Mar 2024 18:45:52 +0100 Subject: [PATCH] fixed tests Signed-off-by: munishchouhan --- app/src/main/java/io/seqera/wave/cli/App.java | 32 +++++++++++-------- .../groovy/io/seqera/wave/cli/AppTest.groovy | 8 ++--- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/seqera/wave/cli/App.java b/app/src/main/java/io/seqera/wave/cli/App.java index abbb003..68e709a 100644 --- a/app/src/main/java/io/seqera/wave/cli/App.java +++ b/app/src/main/java/io/seqera/wave/cli/App.java @@ -200,7 +200,7 @@ public class App implements Runnable { List includes; @Option(names = {"--label"}, paramLabel = "false", description = "Include one or more labels in the wave build image. e.g. KEY=VALUE") - List label; + List labels; public static void main(String[] args) { try { @@ -385,8 +385,8 @@ protected void validateArgs() { throw new IllegalCliArgumentException(String.format("Unsupported container platform: '%s'", platform)); // check labels - if( label!=null ) { - for( String it : label) { + if( labels!=null ) { + for( String it : labels) { if( !isLabel(it) ) throw new IllegalCliArgumentException("Invalid docker label syntax - offending value: " + it); } } @@ -571,20 +571,26 @@ protected ContainerConfig prepareConfig() { if( size>=10 * _1MB ) throw new RuntimeException("Compressed container layers cannot exceed 10 MiB"); - Map labels = null; - if(label!=null){ - labels = new HashMap<>(); - for(String singleLabel: label){ - String[] singleLabelArray = singleLabel.split("="); - labels.put(singleLabelArray[0], singleLabelArray[1]); - } - } - - result.labels = labels; + result.labels = createLablesMap(labels); // return the result + System.out.println("labels: " + labels); + System.out.println("Container config: " + result); return !result.empty() ? result : null; } + private Map createLablesMap(List labelList) { + if( labelList != null){ + return labelList.stream() + .map(entry -> entry.split("=")) + .filter(keyValue -> keyValue.length == 2) + .collect(Collectors.toMap( + keyValue -> keyValue[0], + keyValue -> keyValue[1])); + } + return null; + } + + private ContainerInspectRequest inspectRequest(String image) { return new ContainerInspectRequest() .withContainerImage(image) diff --git a/app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy b/app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy index 98b94c8..a8c9ea4 100644 --- a/app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy +++ b/app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy @@ -279,13 +279,13 @@ class AppTest extends Specification { when: new CommandLine(app).parseArgs(args) then: - app.@label[0] == "key1=value1" - app.@label[1] == "key2=value2" + app.@labels[0] == "key1=value1" + app.@labels[1] == "key2=value2" when: - def request = app.createRequest() + def config = app.prepareConfig() then: - request.labels == [ + config.labels == [ "key1":"value1", "key2":"value2" ]