Skip to content

Commit

Permalink
fixed image strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
munishchouhan committed May 21, 2024
1 parent 08b17e4 commit 137217d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@
"queryAllDeclaredMethods":true,
"methods":[{"name":"toJson","parameterTypes":["io.seqera.wave.core.spec.ObjectRef"] }]
},
{
"name":"io.seqera.wave.cli.json.ImageNameStrategyAdapter",
"queryAllDeclaredMethods":true,
"methods":[{"name":"toJson","parameterTypes":["io.seqera.wave.api.ImageNameStrategy"] }, {"name":"fromJson","parameterTypes":["java.lang.String"] }]
},
{
"name":"io.seqera.wave.cli.model.ContainerInspectResponseEx",
"allDeclaredFields":true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2024, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package io.seqera.wave.cli.json;

import com.squareup.moshi.FromJson;
import com.squareup.moshi.ToJson;
import io.seqera.wave.api.ImageNameStrategy;
/**
* Image Name Strategy adapter for Moshi JSON serialisation
*
* @author Munish Chouhan <[email protected]>
*/
public class ImageNameStrategyAdapter {

@ToJson
public String toJson(ImageNameStrategy strategy) {
return strategy.name();
}

@FromJson
public ImageNameStrategy fromJson(String strategy) {
return ImageNameStrategy.valueOf(strategy);
}
}
1 change: 1 addition & 0 deletions app/src/main/java/io/seqera/wave/cli/json/JsonHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class JsonHelper {
.add(new DateTimeAdapter())
.add(new PathAdapter())
.add(new LayerRefAdapter())
.add(new ImageNameStrategyAdapter())
.build();

public static String toJson(SubmitContainerTokenRequest request) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,22 @@ class AppTest extends Specification {
app.@nameStrategy == ImageNameStrategy.tagPrefix
}

def 'should get the correct name strategy'(){
given:
def app = new App()
String[] args = ["-i", "ubuntu:latest", "--name-strategy", "imageSuffix"]

when:
def cli = new CommandLine(app)
cli.parseArgs(args)
and:
app.validateArgs()
then:
noExceptionThrown()
and:
app.@nameStrategy == ImageNameStrategy.imageSuffix
}

def 'should fail when passing incorrect name strategy'(){
given:
def app = new App()
Expand Down

0 comments on commit 137217d

Please sign in to comment.