Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
Signed-off-by: munishchouhan <[email protected]>
  • Loading branch information
munishchouhan committed Mar 18, 2024
1 parent 445b537 commit 2ec9032
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
32 changes: 19 additions & 13 deletions app/src/main/java/io/seqera/wave/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public class App implements Runnable {
List<String> includes;

@Option(names = {"--label"}, paramLabel = "false", description = "Include one or more labels in the wave build image. e.g. KEY=VALUE")
List<String> label;
List<String> labels;

public static void main(String[] args) {
try {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -571,20 +571,26 @@ protected ContainerConfig prepareConfig() {
if( size>=10 * _1MB )
throw new RuntimeException("Compressed container layers cannot exceed 10 MiB");

Map<String, String> 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<String, String> createLablesMap(List<String> 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)
Expand Down
8 changes: 4 additions & 4 deletions app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down

0 comments on commit 2ec9032

Please sign in to comment.