Skip to content

Commit

Permalink
add new hb.cran.dev url, and a bit more error catching for urls
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jul 19, 2024
1 parent 9c7eea3 commit 0176536
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
31 changes: 18 additions & 13 deletions tests/testthat/helper-vcr.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,29 @@ sm <- function(x) suppressMessages(x)


# Base url for tests
hb <- function(x = NULL) if (is.null(x)) base_url else paste0(base_url, x)
hb <- function(x = NULL) {
tryCatch(
if (is.null(x)) base_url else paste0(base_url, x),
error = function(e) "https://not.aurl"
)
}
urls <- c(
"https://hb.cran.dev",
"https://hb.opencpu.org",
"https://nghttp2.org/httpbin"
)
h <- curl::new_handle(timeout = 5, failonerror = FALSE)
out <- list()
for (i in seq_along(urls)) {
tryCatch({
h <- curl::new_handle(timeout = 10, failonerror = FALSE)
base_url <- ""
tryCatch({
out <- list()
for (i in seq_along(urls)) {
out[[i]] <- curl::curl_fetch_memory(urls[i], handle = h)
}, error = function(e)
message(urls[i], " is down ", e$message)
)
}
codes <- vapply(out, "[[", 1, "status_code")
if (!any(codes == 200)) stop("all httpbin servers down")
base_url <- urls[codes == 200][1]
cat(paste0("using base url for tests: ", base_url), sep = "\n")
}
codes <- vapply(out, "[[", 1, "status_code")
if (all(codes != 200)) stop("all httpbin servers down")
base_url <- urls[codes == 200][1]
cat(paste0("using base url for tests: ", base_url), sep = "\n")
}, error = function(e) message(e$message))

# httpbin local
local_httpbin_app <- function() {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-request_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ test_that("request_summary works", {
expect_is(cc, "character")
expect_is(dd, "character")

expect_match(aa, "post .+org/")
expect_match(bb, "post .+org/ foo=bar")
expect_match(aa, "post .+/")
expect_match(bb, "post .+/ foo=bar")

expect_match(cc, "post")
expect_match(cc, ".org")
expect_match(cc, ".+")
expect_match(cc, "libcurl")
expect_match(cc, "r-curl")
expect_match(cc, "crul")
Expand All @@ -37,7 +37,7 @@ test_that("request_summary works", {
expect_false(grepl("foo=bar", cc))

expect_match(dd, "post")
expect_match(dd, ".org")
expect_match(dd, ".+")
expect_match(dd, "foo=bar")
expect_match(dd, "libcurl")
expect_match(dd, "r-curl")
Expand Down

0 comments on commit 0176536

Please sign in to comment.