-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #5 add tests mocking requests, add suggest pkgs jsonlite and webm…
…ockr
- Loading branch information
Showing
8 changed files
with
244 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
library(webmockr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
response_status_running <- list( | ||
canJobStart = FALSE, | ||
jobStatus = "RUNNING", | ||
cromwellUrl = "https://some.url", | ||
jobInfo = list( | ||
WORKFLOWLOGDIR = "/some/path", | ||
SCRATCHDIR = "/some/path", | ||
SLURM_JOB_ID = "someid", | ||
CROMWELL_DIR = "/some/path", | ||
SERVERLOGDIR = "/some/path", | ||
SINGULARITY_CACHEDIR = "/some/path", | ||
SERVERTIME = "1-0", | ||
USE_AWS = FALSE, | ||
SLURM_JOB_ACCOUNT = "/some/path" | ||
) | ||
) | ||
|
||
response_status_not_running <- list( | ||
canJobStart = TRUE, | ||
jobStatus = NULL, | ||
cromwellUrl = NULL, | ||
jobInfo = list( | ||
WORKFLOWLOGDIR = NULL, | ||
SCRATCHDIR = NULL, | ||
SLURM_JOB_ID = NULL, | ||
CROMWELL_DIR = NULL, | ||
SERVERLOGDIR = NULL, | ||
SINGULARITY_CACHEDIR = NULL, | ||
SERVERTIME = NULL, | ||
USE_AWS = NULL, | ||
SLURM_JOB_ACCOUNT = NULL | ||
) | ||
) | ||
|
||
response_start_success <- list( | ||
job_id = "12345678", | ||
info = "Job submitted successfully. Some message" | ||
) | ||
|
||
response_start_conflict <- list( | ||
message = "Job is already running" | ||
) | ||
|
||
response_cancel_success <- list( | ||
message = "Proof/cromwell job for user xxxxx has been cancelled" | ||
) | ||
|
||
response_cancel_conflict <- list( | ||
message = "Job is not running, nothing to delete" | ||
) | ||
|
||
response_authenticate_success <- list( | ||
username = "jane", | ||
token = "somerandomstring", | ||
server_url = NULL, | ||
proxy_url = NULL, | ||
job_id = NULL, | ||
token_creation_date = NULL | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
test_that("proof_authenticate - error behavior", { | ||
# errors if no username supplied | ||
expect_error(proof_authenticate(), | ||
'"username" is missing') | ||
|
||
# errors if no password supplied | ||
expect_error(proof_authenticate(username = "apple"), | ||
'"password" is missing') | ||
|
||
# username should be character | ||
expect_error(proof_authenticate(5), | ||
'username must be of class character') | ||
|
||
# password should be character | ||
expect_error(proof_authenticate(username = "apple", password = 5), | ||
'password must be of class character') | ||
}) | ||
|
||
test_that("proof_start - success", { | ||
stub_registry_clear() | ||
stub_request("post", make_url("authenticate")) %>% | ||
to_return( | ||
body = jsonlite::toJSON( | ||
response_authenticate_success, auto_unbox = TRUE), | ||
status = 200L, | ||
headers = list('Content-type' = "application/json") | ||
) | ||
stub_registry() | ||
|
||
enable(quiet = TRUE) | ||
|
||
auth_res <- proof_authenticate("jane", "faketoken") | ||
|
||
expect_type(auth_res, "character") | ||
expect_equal(auth_res, "somerandomstring") | ||
|
||
|
||
stub_registry_clear() | ||
disable(quiet = TRUE) | ||
Sys.unsetenv("PROOF_TOKEN") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
test_that("proof_cancel - success", { | ||
stub_registry_clear() | ||
stub_request("delete", make_url("cromwell-server")) %>% | ||
to_return( | ||
body = jsonlite::toJSON(response_cancel_success, auto_unbox = TRUE), | ||
status = 200L, | ||
headers = list('Content-type' = "application/json") | ||
) | ||
stub_registry() | ||
|
||
enable(quiet = TRUE) | ||
|
||
withr::with_envvar(c("PROOF_TOKEN" = "notarealtoken"), { | ||
cancel_res <- proof_cancel() | ||
}) | ||
|
||
expect_type(cancel_res, "list") | ||
expect_type(cancel_res$message, "character") | ||
expect_match(cancel_res$message, "cancelled") | ||
|
||
|
||
stub_registry_clear() | ||
disable(quiet = TRUE) | ||
}) | ||
|
||
test_that("proof_cancel - not running, can not cancel", { | ||
stub_request("delete", make_url("cromwell-server")) %>% | ||
to_return( | ||
body = jsonlite::toJSON(response_cancel_conflict, auto_unbox = TRUE), | ||
status = 409L, | ||
headers = list('Content-type' = "application/json") | ||
) | ||
|
||
enable(quiet = TRUE) | ||
|
||
withr::with_envvar(c("PROOF_TOKEN" = "notarealtoken"), { | ||
expect_error(proof_cancel(), "Job is not running, nothing to delete") | ||
}) | ||
|
||
|
||
stub_registry_clear() | ||
disable(quiet = TRUE) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
test_that("proof_start - success", { | ||
stub_request("post", make_url("cromwell-server")) %>% | ||
to_return( | ||
body = jsonlite::toJSON(response_start_success, auto_unbox = TRUE), | ||
status = 200L, | ||
headers = list('Content-type' = "application/json") | ||
) | ||
|
||
enable(quiet = TRUE) | ||
|
||
withr::with_envvar(c("PROOF_TOKEN" = "notarealtoken"), { | ||
start_res <- proof_start() | ||
}) | ||
|
||
expect_type(start_res, "list") | ||
expect_type(start_res$job_id, "character") | ||
expect_type(start_res$info, "character") | ||
|
||
|
||
stub_registry_clear() | ||
disable(quiet = TRUE) | ||
}) | ||
|
||
test_that("proof_start - already running", { | ||
stub_request("post", make_url("cromwell-server")) %>% | ||
to_return( | ||
body = jsonlite::toJSON(response_start_conflict, auto_unbox = TRUE), | ||
status = 409L, | ||
headers = list('Content-type' = "application/json") | ||
) | ||
|
||
enable(quiet = TRUE) | ||
|
||
withr::with_envvar(c("PROOF_TOKEN" = "notarealtoken"), { | ||
expect_error(proof_start(), "Job is already running") | ||
}) | ||
|
||
|
||
stub_registry_clear() | ||
disable(quiet = TRUE) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
test_that("proof_status - server IS running", { | ||
stub_request("get", make_url("cromwell-server")) %>% | ||
to_return( | ||
body = jsonlite::toJSON( | ||
response_status_running, auto_unbox = TRUE, null = "null"), | ||
status = 200L, | ||
headers = list('Content-type' = "application/json") | ||
) | ||
|
||
enable(quiet = TRUE) | ||
|
||
withr::with_envvar(c("PROOF_TOKEN" = "notarealtoken"), { | ||
status_res <- proof_status() | ||
}) | ||
|
||
expect_type(status_res, "list") | ||
expect_type(status_res$canJobStart, "logical") | ||
expect_type(status_res$jobStatus, "character") | ||
expect_type(status_res$cromwellUrl, "character") | ||
expect_type(status_res$jobInfo, "list") | ||
for (item in status_res$jobInfo) { | ||
expect_true(inherits(item, c("character", "logical"))) | ||
} | ||
|
||
|
||
stub_registry_clear() | ||
disable(quiet = TRUE) | ||
}) | ||
|
||
test_that("proof_status - server IS NOT running", { | ||
stub_request("get", make_url("cromwell-server")) %>% | ||
to_return( | ||
body = jsonlite::toJSON( | ||
response_status_not_running, auto_unbox = TRUE, null = "null"), | ||
status = 200L, | ||
headers = list('Content-type' = "application/json") | ||
) | ||
|
||
enable(quiet = TRUE) | ||
|
||
withr::with_envvar(c("PROOF_TOKEN" = "notarealtoken"), { | ||
status_res <- proof_status() | ||
}) | ||
|
||
expect_type(status_res, "list") | ||
expect_type(status_res$canJobStart, "logical") | ||
expect_null(status_res$jobStatus) | ||
expect_null(status_res$cromwellUrl) | ||
expect_type(status_res$jobInfo, "list") | ||
for (item in status_res$jobInfo) expect_null(item) | ||
|
||
|
||
stub_registry_clear() | ||
disable(quiet = TRUE) | ||
}) |