mock_dir <- function(req) { if (req$method != "PROPFIND") { httr2::response(body = 405) } else { if (req$url == "https://cloud.example.com/test") { httr2::response(status_code = 207, header = list("Content-Type" = "application/xml"), body = charToRaw(' /test/ Wed, 28 Feb 2024 21:30:45 GMT 41 527309756657 "65dfa6056af07" HTTP/1.1 200 OK /test/a.csv Wed, 28 Feb 2024 21:30:45 GMT 26 "433f89eafeada7a93501f5b2d0c05651" text/csv HTTP/1.1 200 OK /test/file.txt Wed, 28 Feb 2024 21:28:32 GMT 15 "ff938d81afc36821bb417c98a8e4f2eb" text/plain HTTP/1.1 200 OK /test/tmp/ Wed, 28 Feb 2024 21:29:42 GMT 0 527309756657 "65dfa5c6d4cbe" HTTP/1.1 200 OK ')) } else if ( req$url == "https://cloud.example.com/file.txt" || req$url == "https://cloud.example.com/") { httr2::response(status_code = 207, header = list("Content-Type" = "application/xml"), body = charToRaw(' /file.txt Wed, 28 Feb 2024 21:17:51 GMT 15 "763a11253670561a3f03defbbb2f5921" text/plain HTTP/1.1 200 OK ')) } else { httr2::response(status_code = 404) } } } test_that("dir works", { r <- httr2::request("https://cloud.example.com") expect_equal( httr2::with_mocked_responses(mock_dir, wd_dir(r, "test")), c("a.csv", "file.txt", "tmp") ) }) test_that("dir file works", { r <- httr2::request("https://cloud.example.com/") expect_equal( httr2::with_mocked_responses(mock_dir, wd_dir(r, "file.txt")), character(0) ) }) test_that("dir full path works", { r <- httr2::request("https://cloud.example.com") expect_equal( httr2::with_mocked_responses( mock_dir, wd_dir(r, "test", full_names = TRUE) ), c("test/a.csv", "test/file.txt", "test/tmp/") ) }) test_that("dir as_df works", { r <- httr2::request("https://cloud.example.com") df <- httr2::with_mocked_responses(mock_dir, wd_dir(r, "test", as_df = TRUE)) expect_equal(nrow(df), 3) expect_equal(df$contenttype, c("text/csv", "text/plain", NA)) }) test_that("dir file as_df works", { r <- httr2::request("https://cloud.example.com") df <- httr2::with_mocked_responses( mock_dir, wd_dir(r, "file.txt", as_df = TRUE) ) expect_equal(nrow(df), 1) expect_equal(df$contenttype, "text/plain") }) test_that("dir error", { r <- httr2::request("https://cloud.example.com/") expect_warning( httr2::with_mocked_responses(mock_dir, wd_dir(r, "testx")), "Not Found" ) }) test_that("dir main", { r <- httr2::request("https://cloud.example.com") expect_equal( httr2::with_mocked_responses(mock_dir, wd_dir(r)), character(0) ) })