From 810576ba73ed3755f063c09faf8a3eed4408e5d4 Mon Sep 17 00:00:00 2001 From: Jeroen Ooms Date: Wed, 9 Aug 2023 11:08:47 +0200 Subject: [PATCH] Add test for seeking --- R/upload.R | 2 ++ tests/testthat/test-seek.R | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/testthat/test-seek.R diff --git a/R/upload.R b/R/upload.R index de7b23bd..b6f1b402 100644 --- a/R/upload.R +++ b/R/upload.R @@ -38,6 +38,8 @@ curl_upload <- function(file, url, verbose = TRUE, reuse = TRUE, ...) { } } return(buf) + }, seekfunction = function(offset){ + seek(con, where = offset) }, forbid_reuse = !isTRUE(reuse), verbose = verbose, ...) if(!is.na(infilesize)){ handle_setopt(h, infilesize_large = infilesize) diff --git a/tests/testthat/test-seek.R b/tests/testthat/test-seek.R new file mode 100644 index 00000000..2b72a3c8 --- /dev/null +++ b/tests/testthat/test-seek.R @@ -0,0 +1,15 @@ +context("Seek") + +test_that("Seeking works after redirect",{ + skip_on_cran() + str <- paste(letters, collapse = '') + tmp <- tempfile() + writeBin(str, tmp) + url <- httpbin('/redirect-to?url=/put&status_code=307') + req <- curl::curl_upload(tmp, url, verbose = FALSE) + headers <- curl::parse_headers(req$headers, multiple = TRUE) + expect_length(headers, 2) + expect_equal(req$status_code, 200) + content <- jsonlite::fromJSON(rawToChar(req$content))$data + expect_equal(content, str) +})