Skip to content

Commit 16908bb

Browse files
committed
Fix tests
Signed-off-by: Paolo Di Tommaso <[email protected]>
1 parent 6b7a8e9 commit 16908bb

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

app/conf/reflect-config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
},
267267
{
268268
"name":"io.seqera.wave.api.PackagesSpec$Type",
269-
"fields":[{"name":"CONDA"}]
269+
"fields":[{"name":"CONDA"}, {"name":"SPACK"}]
270270
},
271271
{
272272
"name":"io.seqera.wave.api.ScanLevel",
@@ -365,6 +365,11 @@
365365
"allDeclaredFields":true,
366366
"methods":[{"name":"<init>","parameterTypes":[] }]
367367
},
368+
{
369+
"name":"io.seqera.wave.config.SpackOpts",
370+
"allDeclaredFields":true,
371+
"methods":[{"name":"<init>","parameterTypes":[] }]
372+
},
368373
{
369374
"name":"io.seqera.wave.core.spec.ConfigSpec",
370375
"allDeclaredFields":true,

app/src/main/java/io/seqera/wave/cli/App.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import io.seqera.wave.config.CondaOpts;
5858
import io.seqera.wave.util.DockerIgnoreFilter;
5959
import io.seqera.wave.util.Packer;
60+
import org.apache.commons.lang3.StringUtils;
6061
import org.slf4j.LoggerFactory;
6162
import picocli.CommandLine;
6263
import static io.seqera.wave.cli.util.Checkers.isEmpty;
@@ -441,7 +442,7 @@ public void run() {
441442
SubmitContainerTokenResponse resp = client.submit(request);
442443
// await build to be completed
443444
if( await != null && resp.status!=null && resp.status!=ContainerStatus.DONE ) {
444-
ContainerStatusResponse status = client.awaitReadiness(resp.requestId, await);
445+
ContainerStatusResponse status = client.awaitCompletion(resp.requestId, await);
445446
// print the wave container name
446447
System.out.println(dumpOutput(new SubmitContainerTokenResponseEx(resp, status)));
447448
}
@@ -620,6 +621,18 @@ protected PackagesSpec packagesSpec() {
620621
return null;
621622
}
622623

624+
protected String dumpOutput(SubmitContainerTokenResponseEx resp) {
625+
if( outputFormat==null && !resp.succeeded ) {
626+
String message = "Container provisioning did not complete successfully";
627+
if( !StringUtils.isEmpty(resp.reason) )
628+
message += "\n- Reason: " + resp.reason;
629+
if( !StringUtils.isEmpty(resp.detailsUri) )
630+
message += "\n- Find out more here: " + resp.detailsUri;
631+
throw new BadClientResponseException(message);
632+
}
633+
return dumpOutput((SubmitContainerTokenResponse)resp);
634+
}
635+
623636
protected String dumpOutput(SubmitContainerTokenResponse resp) {
624637
if( "yaml".equals(outputFormat) ) {
625638
return YamlHelper.toYaml(resp);

app/src/main/java/io/seqera/wave/cli/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected URI imageToManifestUri(String image) {
199199
return URI.create(result);
200200
}
201201

202-
ContainerStatusResponse awaitReadiness(String requestId, Duration await) {
202+
ContainerStatusResponse awaitCompletion(String requestId, Duration await) {
203203
if( StringUtils.isEmpty(requestId) )
204204
throw new IllegalArgumentException("Argument 'requestId' cannot be empty");
205205
log.debug("Waiting for build completion: {} - timeout: {} Seconds", requestId, await.toSeconds());

app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import io.seqera.wave.api.ImageNameStrategy
2727
import io.seqera.wave.api.ScanLevel
2828
import io.seqera.wave.api.ScanMode
2929
import io.seqera.wave.api.SubmitContainerTokenResponse
30+
import io.seqera.wave.cli.exception.BadClientResponseException
3031
import io.seqera.wave.cli.exception.IllegalCliArgumentException
3132
import io.seqera.wave.cli.model.ContainerInspectResponseEx
3233
import io.seqera.wave.cli.model.SubmitContainerTokenResponseEx
@@ -134,6 +135,45 @@ class AppTest extends Specification {
134135
'''.stripIndent(true)
135136
}
136137

138+
def 'should throw exception on failure' (){
139+
given:
140+
def app = new App()
141+
String[] args = []
142+
and:
143+
def resp = new SubmitContainerTokenResponse(
144+
containerToken: "12345",
145+
targetImage: 'docker.io/some/repo',
146+
containerImage: 'docker.io/some/container',
147+
expiration: Instant.ofEpochMilli(1691839913),
148+
buildId: '98765',
149+
cached: false
150+
)
151+
def status = new ContainerStatusResponse(
152+
"12345",
153+
ContainerStatus.DONE,
154+
"98765",
155+
null,
156+
"scan-1234",
157+
[MEDIUM:1, HIGH:2],
158+
false,
159+
"Something went wrong",
160+
"http://foo.com/bar/1234",
161+
Instant.now(),
162+
Duration.ofMinutes(1)
163+
)
164+
165+
when:
166+
new CommandLine(app).parseArgs(args)
167+
app.dumpOutput(new SubmitContainerTokenResponseEx(resp, status))
168+
then:
169+
def e = thrown(BadClientResponseException)
170+
e.message == '''\
171+
Container provisioning did not complete successfully
172+
- Reason: Something went wrong
173+
- Find out more here: http://foo.com/bar/1234\
174+
'''.stripIndent()
175+
}
176+
137177
def 'should dump response to json' () {
138178
given:
139179
def app = new App()

0 commit comments

Comments
 (0)