mock_isdir <- function(req) {
if (req$method != "PROPFIND") {
httr2::response(body = 405)
} else {
if (req$url == "https://cloud.example.com/test") {
httr2::response(status_code = 207,
headers = list("Content-Type" = "application/xml"),
body = charToRaw('
/test/
HTTP/1.1 200 OK
'))
} else if (req$url == "https://cloud.example.com/file.txt") {
httr2::response(status_code = 207,
headers = list("Content-Type" = "application/xml"),
body = charToRaw('
/file.txt
HTTP/1.1 200 OK
'))
} else {
httr2::response(status_code = 404)
}
}
}
test_that("is dir works", {
r <- httr2::request("https://cloud.example.com")
expect_equal(
httr2::with_mocked_responses(mock_isdir, wd_isdir(r, "test")),
TRUE
)
})
test_that("is not dir works", {
r <- httr2::request("https://cloud.example.com")
expect_equal(
httr2::with_mocked_responses(mock_isdir, wd_isdir(r, "file.txt")),
FALSE
)
})
test_that("dir warning", {
r <- httr2::request("https://cloud.example.com")
expect_warning(
httr2::with_mocked_responses(mock_isdir, wd_isdir(r, "testx")),
"Not Found"
)
})