Skip to content

Commit 0b7b6c8

Browse files
committed
Fix tests if some HTTP options are already set
1 parent c01d63f commit 0b7b6c8

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/testthat/test-4-async-http.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
local_clear_http_options <- function(.local_envir = parent.frame()) {
2+
nms <- c(
3+
"timeout",
4+
"connecttimeout",
5+
"low_speed_time",
6+
"low_speed_limit",
7+
"http_version"
8+
)
9+
opts <- c(paste0("pkgcache_", nms), paste0("pkg_http_", nms))
10+
withr::local_options(
11+
structure(vector("list", length(opts)), names = opts),
12+
.local_envir = .local_envir
13+
)
14+
envs <- c(
15+
paste0("PKGCACHE_", toupper(nms)),
16+
paste0("PKG_HTTP_", toupper(nms))
17+
)
18+
withr::local_envvar(
19+
structure(rep(NA_character_, length(envs)), names = envs),
20+
.local_envir = .local_envir
21+
)
22+
}
23+
124
test_that("read_etag", {
225
cat("foobar\n", file = tmp <- tempfile())
326
expect_equal(read_etag(tmp), "foobar")
@@ -314,6 +337,8 @@ test_that("download_files, no errors", {
314337
})
315338

316339
test_that("set_pkgcache_curl_options", {
340+
local_clear_http_options()
341+
317342
# nothing configured: leave the options untouched, no defaults added
318343
expect_equal(set_pkgcache_curl_options(list()), list())
319344
expect_equal(set_pkgcache_curl_options(list(foo = "bar")), list(foo = "bar"))
@@ -362,6 +387,8 @@ test_that("set_pkgcache_curl_options", {
362387
})
363388

364389
test_that("set_pkgcache_curl_options, pkg_http_ fallback", {
390+
local_clear_http_options()
391+
365392
# pkg_http_* option is used when nothing with higher priority is set
366393
withr::local_options(pkg_http_http_version = 2)
367394
expect_equal(set_pkgcache_curl_options(list())$http_version, 2L)

0 commit comments

Comments
 (0)