Skip to content

Commit

Permalink
fix: update pipeline test
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeSeqLabs committed Aug 29, 2023
1 parent 34c5f77 commit 95d0ccc
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions src/test/java/io/seqera/tower/cli/pipelines/PipelinesCmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ void testUpdate(MockServerClient mock) {
);

mock.when(
request().withMethod("PUT").withPath("/pipelines/217997727159863").withBody("{\"description\":\"Sleep one minute and exit\",\"launch\":{\"computeEnvId\":\"vYOK4vn7spw7bHHWBDXZ2\",\"pipeline\":\"https://github.com/pditommaso/nf-sleep\",\"workDir\":\"s3://nextflow-ci/jordeu\",\"paramsText\":\"timeout: 60\\n\",\"pullLatest\":false,\"stubRun\":false}}"), exactly(1)
request().withMethod("PUT").withPath("/pipelines/217997727159863")
.withBody(json("{\"description\":\"Sleep one minute and exit\",\"name\":\"sleep_one_minute\",\"launch\":{\"computeEnvId\":\"vYOK4vn7spw7bHHWBDXZ2\",\"pipeline\":\"https://github.com/pditommaso/nf-sleep\",\"workDir\":\"s3://nextflow-ci/jordeu\",\"paramsText\":\"timeout: 60\\n\",\"pullLatest\":false,\"stubRun\":false}}")), exactly(1)
).respond(
response().withStatusCode(200).withBody("{\"pipeline\":{\"pipelineId\":217997727159863,\"name\":\"sleep_one_minute\",\"description\":\"Sleep one minute and exit\",\"icon\":null,\"repository\":\"https://github.com/pditommaso/nf-sleep\",\"userId\":4,\"userName\":\"jordi\",\"userFirstName\":null,\"userLastName\":null,\"orgId\":null,\"orgName\":null,\"workspaceId\":null,\"workspaceName\":null,\"visibility\":null}}").withContentType(MediaType.APPLICATION_JSON)
);
Expand Down Expand Up @@ -121,7 +122,8 @@ void testUpdateComputeEnv(MockServerClient mock) {
);

mock.when(
request().withMethod("PUT").withPath("/pipelines/217997727159863").withBody("{\"launch\":{\"computeEnvId\":\"isnEDBLvHDAIteOEF44ow\",\"pipeline\":\"https://github.com/pditommaso/nf-sleep\",\"workDir\":\"s3://nextflow-ci/jordeu\",\"paramsText\":\"timeout: 60\\n\",\"pullLatest\":false,\"stubRun\":false}}"), exactly(1)
request().withMethod("PUT").withPath("/pipelines/217997727159863")
.withBody(json("{\"name\":\"sleep_one_minute\",\"launch\":{\"computeEnvId\":\"isnEDBLvHDAIteOEF44ow\",\"pipeline\":\"https://github.com/pditommaso/nf-sleep\",\"workDir\":\"s3://nextflow-ci/jordeu\",\"paramsText\":\"timeout: 60\\n\",\"pullLatest\":false,\"stubRun\":false}}")), exactly(1)
).respond(
response().withStatusCode(200).withBody("{\"pipeline\":{\"pipelineId\":217997727159863,\"name\":\"sleep_one_minute\",\"description\":\"Sleep one minute and exit\",\"icon\":null,\"repository\":\"https://github.com/pditommaso/nf-sleep\",\"userId\":4,\"userName\":\"jordi\",\"userFirstName\":null,\"userLastName\":null,\"orgId\":null,\"orgName\":null,\"workspaceId\":null,\"workspaceName\":null,\"visibility\":null}}").withContentType(MediaType.APPLICATION_JSON)
);
Expand Down Expand Up @@ -163,21 +165,48 @@ void testUpdatePipelineName(MockServerClient mock) {
).respond(
response().withStatusCode(204)
);

ExecOut out = exec(mock, "pipelines", "update", "-n", "sleep_one_minute", "--new-name", "sleepOneMinute");

assertEquals("", out.stdErr);
assertEquals(new PipelinesUpdated(USER_WORKSPACE_NAME, "sleep_one_minute").toString(), out.stdOut);

}

@Test
void testUpdatePipelineInvalidName(MockServerClient mock) {

mock.reset();

mock.when(
request().withMethod("GET").withPath("/pipelines").withQueryStringParameter("search", "sleep_one_minute")
).respond(
response().withStatusCode(200).withBody("{\"pipelines\":[{\"pipelineId\":217997727159863,\"name\":\"sleep_one_minute\",\"description\":null,\"icon\":null,\"repository\":\"https://github.com/pditommaso/nf-sleep\",\"userId\":4,\"userName\":\"jordi\",\"userFirstName\":null,\"userLastName\":null,\"orgId\":null,\"orgName\":null,\"workspaceId\":null,\"workspaceName\":null,\"visibility\":null}],\"totalSize\":1}").withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/pipelines/217997727159863/launch")
).respond(
response().withStatusCode(200).withBody(loadResource("pipelines_update")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("PUT").withPath("/pipelines/217997727159863")
.withBody(json("{\"name\": \"sleepOneMinute\", \"launch\":{\"computeEnvId\":\"vYOK4vn7spw7bHHWBDXZ2\",\"pipeline\":\"https://github.com/pditommaso/nf-sleep\",\"workDir\":\"s3://nextflow-ci/jordeu\",\"paramsText\":\"timeout: 60\\n\",\"pullLatest\":false,\"stubRun\":false}}")),
exactly(1)
).respond(
response().withStatusCode(200)
.withBody("{\"pipeline\":{\"pipelineId\":217997727159863,\"name\":\"sleepOneMinute\",\"description\":\"Sleep one minute and exit\",\"icon\":null,\"repository\":\"https://github.com/pditommaso/nf-sleep\",\"userId\":4,\"userName\":\"jordi\",\"userFirstName\":null,\"userLastName\":null,\"orgId\":null,\"orgName\":null,\"workspaceId\":null,\"workspaceName\":null,\"visibility\":null}}").withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/pipelines/validate").withQueryStringParameter("name", "#sleep")
).respond(
response().withStatusCode(400)
.withBody(json("{\"message\": \"Pipeline name must contain a minimum of 2 and a maximum of 99 alphanumeric characters separated by dashes or underscores\"}"))
);

// successful update
ExecOut out = exec(mock, "pipelines", "update", "-n", "sleep_one_minute", "--new-name", "sleepOneMinute");

assertEquals("", out.stdErr);
assertEquals(new PipelinesUpdated(USER_WORKSPACE_NAME, "sleep_one_minute").toString(), out.stdOut);

// must fail with invalid name
out = exec(mock, "pipelines", "update", "-n", "sleep_one_minute", "--new-name", "#sleep");
ExecOut out = exec(mock, "pipelines", "update", "-n", "sleep_one_minute", "--new-name", "#sleep");

assertEquals(errorMessage(out.app, new InvalidResponseException("Pipeline name '#sleep' is not valid")), out.stdErr);
assertEquals("", out.stdOut);
Expand Down

0 comments on commit 95d0ccc

Please sign in to comment.