Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't expect error #555

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions R/helpers-testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ retrieve_plugins <- function(plugin_name) {
checkmate::assert_character(plugin_name , any.missing = FALSE, min.chars = 2, max.chars = 50)

server_instance <-
# if(Sys.getenv("redcapr_test_server") != "") {
if(Sys.getenv("redcapr_test_server") != "") {
Sys.getenv("redcapr_test_server")
# } else {
# "dev-2"
# }
} else {
message("The test server was not explicitly set for plugins, so defaulting to 'dev-2'.")
"dev-2"
}
checkmate::assert_character(server_instance , any.missing = FALSE, min.chars = 2, max.chars = 50)

# This line avoids a warning from the package check.
Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-event-instruments.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,24 @@ test_that("2-arms-retrieve-only-arm-2", {
test_that("Bad URI", {
testthat::skip_on_cran()
bad_uri <- "https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com"
expected_data_frame <- structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")
# expected_data_frame <- structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")

# Windows gives a different message than Travis/Linux
expected_outcome_message <- "(https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com|Couldn't resolve host 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com')"
# expected_outcome_message <- "(https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com|Couldn't resolve host 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com')"
# "The REDCapR variable retrieval was not successful\\..+?Error 405 \\(Method Not Allowed\\).+"
# expected_outcome_message <- "(?s)The REDCapR variable retrieval was not successful\\..+?.+"

expect_error(
# expect_error(
returned_object <- redcap_event_instruments(
redcap_uri = bad_uri,
token = credential_longitudinal$token,
verbose = FALSE
)
)
# )

expect_false(returned_object$success)
expect_equal(returned_object$status_code, 403L)
expect_match(returned_object$outcome_message, "The REDCapR instrument retrieval was not successful.+")
})
test_that("no-arms", {
testthat::skip_on_cran()
Expand Down
11 changes: 7 additions & 4 deletions tests/testthat/test-instruments-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,24 @@ test_that("default", {
test_that("Bad URI", {
testthat::skip_on_cran()
bad_uri <- "https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com"
expected_data_frame <- structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")
# expected_data_frame <- structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")

# Windows gives a different message than Travis/Linux
expected_outcome_message <- "(https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com|Couldn't resolve host 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com')"
# expected_outcome_message <- "(https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com|Couldn't resolve host 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com')"
# "The REDCapR variable retrieval was not successful\\..+?Error 405 \\(Method Not Allowed\\).+"
# expected_outcome_message <- "(?s)The REDCapR variable retrieval was not successful\\..+?.+"

expect_error(
# expect_error(
returned_object <-
redcap_instruments(
redcap_uri = bad_uri,
token = credential$token,
verbose = FALSE
)
)
# )
expect_false(returned_object$success)
expect_equal(returned_object$status_code, 403L)
expect_match(returned_object$outcome_message, "The REDCapR instrument retrieval was not successful.+")
})

test_that("bad token -Error", {
Expand Down
2 changes: 1 addition & 1 deletion utility/refresh.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ devtools::run_examples(); #dev.off() #This overwrites the NAMESPACE file too
# devtools::run_examples(, "redcap_read.Rd")
# pkgload::load_all()
test_results_checked <- devtools::test()
test_results_checked <- devtools::test(filter = "^retrieve-credential")
test_results_checked <- devtools::test(filter = "^sanitize")
# withr::local_envvar(ONLYREADTESTS = "true")
# test_results_checked <- devtools::test(filter = "write-batch")

Expand Down