From 38909b7fd96bc294495367b11eafe5a64c78b06a Mon Sep 17 00:00:00 2001 From: salvafern Date: Wed, 26 Apr 2023 10:38:32 +0200 Subject: [PATCH] feat: add detritus cleaning but switch off during testing --- R/08_mrp_get.R | 28 +++++++++++++----- R/utils.R | 4 +++ real-tests/testthat/test-real-prod.R | 24 ++++++++++++--- tests/testthat/prod/fail/geo/eez-165a0cf8.zip | 5 ++++ tests/testthat/prod/fail/geo/eez-18c40a19.zip | Bin 0 -> 1330 bytes .../prod/fail/geo/eez-18c40a19/README.TXT | 1 + .../prod/fail/geo/eez-18c40a19/eez.cst | 1 + .../prod/fail/geo/eez-18c40a19/eez.dbf | Bin 0 -> 1025 bytes .../prod/fail/geo/eez-18c40a19/eez.prj | 1 + .../prod/fail/geo/eez-18c40a19/eez.shp | Bin 0 -> 100 bytes .../prod/fail/geo/eez-18c40a19/eez.shx | Bin 0 -> 100 bytes tests/testthat/prod/fail/geo/eez-5664f407.zip | 6 ++++ tests/testthat/prod/fail/geo/eez-9700bc98.zip | 5 ++++ tests/testthat/prod/fail/geo/eez-f5f8f76d.zip | 6 ++++ tests/testthat/prod/fail/geo/ows-8fcb79.R | 6 ++++ tests/testthat/prod/fail/geo/ows-a366ca.R | 2 +- tests/testthat/prod/fail/geo/ows-af137d.R | 2 +- tests/testthat/prod/fail/geo/ows-bf6baa.R | 2 +- tests/testthat/prod/fail/geo/ows-cfb5b6.R | 2 +- tests/testthat/prod/fail/geo/wfs-f93f5d.R | 21 ------------- tests/testthat/test-prod.R | 24 ++++++++++++--- 21 files changed, 99 insertions(+), 41 deletions(-) create mode 100644 tests/testthat/prod/fail/geo/eez-165a0cf8.zip create mode 100644 tests/testthat/prod/fail/geo/eez-18c40a19.zip create mode 100644 tests/testthat/prod/fail/geo/eez-18c40a19/README.TXT create mode 100644 tests/testthat/prod/fail/geo/eez-18c40a19/eez.cst create mode 100644 tests/testthat/prod/fail/geo/eez-18c40a19/eez.dbf create mode 100644 tests/testthat/prod/fail/geo/eez-18c40a19/eez.prj create mode 100644 tests/testthat/prod/fail/geo/eez-18c40a19/eez.shp create mode 100644 tests/testthat/prod/fail/geo/eez-18c40a19/eez.shx create mode 100644 tests/testthat/prod/fail/geo/eez-5664f407.zip create mode 100644 tests/testthat/prod/fail/geo/eez-9700bc98.zip create mode 100644 tests/testthat/prod/fail/geo/eez-f5f8f76d.zip create mode 100644 tests/testthat/prod/fail/geo/ows-8fcb79.R delete mode 100644 tests/testthat/prod/fail/geo/wfs-f93f5d.R diff --git a/R/08_mrp_get.R b/R/08_mrp_get.R index dea410e..0773485 100644 --- a/R/08_mrp_get.R +++ b/R/08_mrp_get.R @@ -109,7 +109,6 @@ mrp_get <- function(layer, path = getOption("mregions2.download_path", tempdir() hash <- glue::glue('{layer}-{hash}') cached_zip_path <- file.path(path, glue::glue('{hash}.zip')) cached_unzip_path <- file.path(path, hash) - dir.create(cached_unzip_path, showWarnings = FALSE) cached_file_path <- file.path(cached_unzip_path, glue::glue('{layer}.shp')) do_request <- TRUE @@ -136,14 +135,14 @@ mrp_get <- function(layer, path = getOption("mregions2.download_path", tempdir() httr2::req_perform(path = cached_zip_path) %>% mrp_get_sanity_check() + dir.create(cached_unzip_path, showWarnings = FALSE) utils::unzip(zipfile = cached_zip_path, exdir = cached_unzip_path, overwrite = TRUE) - # suppressWarnings({ - # try({file.remove(cached_zip_path)}) - # }) - + if(!is_test()) try_clean_up(cached_zip_path) } + check_server_warning(cached_unzip_path) + mrp_list <- NULL # Avoid R CMD Check note out <- sf::st_read(cached_file_path, quiet = TRUE, stringsAsFactors = FALSE) @@ -152,7 +151,7 @@ mrp_get <- function(layer, path = getOption("mregions2.download_path", tempdir() } cache_max_time <- function(){ - weeks <- getOption("TESTPKG.CACHETIME", 4) + weeks <- Sys.getenv("TESTPKG.CACHETIME", 4) weeks } @@ -177,10 +176,10 @@ mrp_get_sanity_check <- function(resp){ msg <- c(msg, "i" = "Exception Code: {.emph {exception_code}}", - "i" = "Exception text: {.emph {exception_text}}" + "i" = "Exception Text: {.emph {exception_text}}" ) - # try({file.remove(resp$body)}) + if(!is_test()) try_clean_up(resp$body) }) cli::cli_abort(msg) } @@ -188,6 +187,19 @@ mrp_get_sanity_check <- function(resp){ resp } +try_clean_up <- function(path) try({file.remove(path)}, silent = TRUE) + +check_server_warning <- function(cached_unzip_path){ + readme <- file.path(cached_unzip_path, "README.txt") + + if(file.exists(readme)){ + msg <- readLines(readme, warn = FALSE, skipNul = TRUE) + msg <- paste0(msg, collapse = "; ") + warning(msg, call. = FALSE) + } + + invisible(NULL) +} .mrp_colnames <- function(layer){ diff --git a/R/utils.R b/R/utils.R index 5a7f0c0..908b93b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -200,3 +200,7 @@ assert_mrgid_exists <- function(mrgid){ gaz_rest_names_by_mrgid(mrgid) invisible(NULL) } + +is_test <- function(){ + nzchar(Sys.getenv("TESTPKG.ISTEST")) +} diff --git a/real-tests/testthat/test-real-prod.R b/real-tests/testthat/test-real-prod.R index 8aea39b..4ad1dbd 100644 --- a/real-tests/testthat/test-real-prod.R +++ b/real-tests/testthat/test-real-prod.R @@ -1,5 +1,9 @@ # httptest2::with_mock_dir("prod/fail/", { test_that("mrp_get: Bad filters errors surfaced", { + # withr::local_options("mregions2.download_path" = "./prod/fail/geo") + withr::local_envvar("TESTPKG.ISTEST" = "true") + withr::local_envvar("TESTPKG.CACHETIME" = 0) + .f <- function() mrp_get("eez", filter="") expect_error(.f(), "XML getFeature request SAX parsing error") @@ -21,6 +25,17 @@ expect_error(.f(), "NoApplicableCode") }) + + test_that("mrp_get: Warnings coming from the server are surfaced", { + # withr::local_options("mregions2.download_path" = "./prod/fail/geo") + withr::local_envvar("TESTPKG.ISTEST" = "true") + withr::local_envvar("TESTPKG.CACHETIME" = 0) + + .f <- function() mrp_get("eez", cql_filter = "mrgid = -1") + expect_warning(.f(), regexp = "empty", fixed = TRUE) + }) + + # }) # httptest2::with_mock_dir("prod/ok/", { @@ -96,6 +111,7 @@ test_that("mrp_get() works", { # withr::local_options("mregions2.download_path" = "./prod/ok/geo") + withr::local_envvar("TESTPKG.ISTEST" = "true") expect_sf <- function(x){ expect_type(x, "list") @@ -105,8 +121,8 @@ } - # Check without caching - withr::local_options("TESTPKG.CACHETIME" = 0) + # Mock HTTP request like if there was no cache + withr::local_envvar("TESTPKG.CACHETIME" = 0) # Mexican ECS Deposit .f1 <- function() mrp_get("ecs", cql_filter = "mrgid = 64123") @@ -118,8 +134,8 @@ expect_sf(.f2()) expect_s3_class(sf::st_geometry(.f2()), "sfc_LINESTRING") - # Check with caching - # withr::local_options("TESTPKG.CACHETIME" = Inf) + # Actually reading from cache without HTTP request + # withr::local_envvar("TESTPKG.CACHETIME" = Inf) # # expect_message(.f1(), "Cache", fixed = TRUE) # expect_sf(.f1()) diff --git a/tests/testthat/prod/fail/geo/eez-165a0cf8.zip b/tests/testthat/prod/fail/geo/eez-165a0cf8.zip new file mode 100644 index 0000000..a21c01f --- /dev/null +++ b/tests/testthat/prod/fail/geo/eez-165a0cf8.zip @@ -0,0 +1,5 @@ + + +Illegal property name: notvalidparameter for feature type MarineRegions:eez + + diff --git a/tests/testthat/prod/fail/geo/eez-18c40a19.zip b/tests/testthat/prod/fail/geo/eez-18c40a19.zip new file mode 100644 index 0000000000000000000000000000000000000000..91f46c0402678f4499b03bd0cb4e2b483bd6d0c2 GIT binary patch literal 1330 zcmWIWW@Zs#;Nak3aCDv(#()Iaf$Y@OD!r7XwAx8`y$%~lwC&HEdwb1q!HEY0QaGAA zJZ=~JS3PsgTPVV_^o*JEYWvVV{Q0TdAFbusq~EE%>Cck|EOPhE{V%Pz{`|b*^yl~L z2@$I2yWO{{J~F=Z*fKRVENG)I%Wu=CmuGzv@VI~Zv-YK|GEQC2u^`}fZ^{-1XaMDORAbb8)Z zeWAK;=63mK`oH-0OPu(5;9>ipQ$RV1NxK`b>WkHFcLvJk^OgRa*0x)BCm(}Yb?~)6 zkNMfw{n4y--^Ww(zvr?}?6gOJJ#rr$iudFHRnPY9_sRY3e;%JW_4M!TiRb38j<|IDBKn#P*wov;3HEV^26cJXHhcYrrL$H6Q^7ac|h21XVJh5&*A zoLpS;ndjT}ts4xsUNL0>YGCKc@qSmp0}OvIAjWL~NH)mT(Z$zQFC-#FwdbNBlOm5x z^i8HU2dr`!&bvzNRB@7EUu|Aq_ikV1`>>AhDe*64He0@8DF0mQIEmfn!{l9;tM5KI z&2jem?3p!f#T>zLp8|KP{oHM^_K}3DWO1&GCv$nwhOZYSVqF``rtQ1hcTgVWx{9kl z7t(-scjI*(Ed3N`6eK4EJWo2n*Ar)8Y_Q?cgp`CI8|0@R;{|(ld6U{H37|nKL>g8> zJ;Mr$vU2<5xtk0`j_yBoWAllB7SH9D9=qeLnHQvJ>(VErwXo;KZS!8G6WgmTpO?S4 z^m>++mbD{@O+}FBfX&vchu+`)dWGTXu47-{%FTGbwmiMz=nF$vwbL=@>o?5!#1bsG zh(TatOG}}XMt3H|rBi8@E8i|_+hoASHbJ@TL7BDc(J4n3hfJwbtmP{$efKHjyZe7; z-s}Hox+vHfT@AV|W%lmD%|T6%;kkRvegg1{jk5z|e8xT4I9e$e`!~+0>ExfV- literal 0 HcmV?d00001 diff --git a/tests/testthat/prod/fail/geo/eez-18c40a19/README.TXT b/tests/testthat/prod/fail/geo/eez-18c40a19/README.TXT new file mode 100644 index 0000000..a2716b3 --- /dev/null +++ b/tests/testthat/prod/fail/geo/eez-18c40a19/README.TXT @@ -0,0 +1 @@ +The query result is empty, and the geometric type of the features is unknwon:an empty point shapefile has been created to fill the zip file \ No newline at end of file diff --git a/tests/testthat/prod/fail/geo/eez-18c40a19/eez.cst b/tests/testthat/prod/fail/geo/eez-18c40a19/eez.cst new file mode 100644 index 0000000..cd89cb9 --- /dev/null +++ b/tests/testthat/prod/fail/geo/eez-18c40a19/eez.cst @@ -0,0 +1 @@ +ISO-8859-1 \ No newline at end of file diff --git a/tests/testthat/prod/fail/geo/eez-18c40a19/eez.dbf b/tests/testthat/prod/fail/geo/eez-18c40a19/eez.dbf new file mode 100644 index 0000000000000000000000000000000000000000..4afc2fa6c9dc789f3a7184525340e85814650fb7 GIT binary patch literal 1025 zcmaKr+e*Vg5Qe8VT2HMOkwQ_V2!e=6l6!CV&WnA85O4{hCR?`g5XJZKRr)HviXhHp z?IL?{Zx;5;|L;Gull~-{0;`!t zUrPC|@quk_@}d4}*X1u+yq*Ytxd$+_rmX$L?>t=BC&ViNpCh;DFIOVZ<`wmiHy%#! zj~OWhdq-~P|K(l(-}ZyNtG^w({IOo!1AiX5^=VG_z(0bV?18WRy!&~Ge+Ies{|a*L Le}cWY`#<~v{hEh# literal 0 HcmV?d00001 diff --git a/tests/testthat/prod/fail/geo/eez-18c40a19/eez.prj b/tests/testthat/prod/fail/geo/eez-18c40a19/eez.prj new file mode 100644 index 0000000..d2e047e --- /dev/null +++ b/tests/testthat/prod/fail/geo/eez-18c40a19/eez.prj @@ -0,0 +1 @@ +GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic latitude", NORTH], AXIS["Geodetic longitude", EAST], AUTHORITY["EPSG","4326"]] \ No newline at end of file diff --git a/tests/testthat/prod/fail/geo/eez-18c40a19/eez.shp b/tests/testthat/prod/fail/geo/eez-18c40a19/eez.shp new file mode 100644 index 0000000000000000000000000000000000000000..25194a3bb47bef31d2f713f52cfc698e5f38740a GIT binary patch literal 100 hcmZQzQ0HR64vbzfGcd4XmjjA^*bk9{(Kr<{0084X1hN1C literal 0 HcmV?d00001 diff --git a/tests/testthat/prod/fail/geo/eez-18c40a19/eez.shx b/tests/testthat/prod/fail/geo/eez-18c40a19/eez.shx new file mode 100644 index 0000000000000000000000000000000000000000..25194a3bb47bef31d2f713f52cfc698e5f38740a GIT binary patch literal 100 hcmZQzQ0HR64vbzfGcd4XmjjA^*bk9{(Kr<{0084X1hN1C literal 0 HcmV?d00001 diff --git a/tests/testthat/prod/fail/geo/eez-5664f407.zip b/tests/testthat/prod/fail/geo/eez-5664f407.zip new file mode 100644 index 0000000..cf321b9 --- /dev/null +++ b/tests/testthat/prod/fail/geo/eez-5664f407.zip @@ -0,0 +1,6 @@ + + +org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 9; XML document structures must start and end within the same entity. +XML document structures must start and end within the same entity. + + diff --git a/tests/testthat/prod/fail/geo/eez-9700bc98.zip b/tests/testthat/prod/fail/geo/eez-9700bc98.zip new file mode 100644 index 0000000..a21c01f --- /dev/null +++ b/tests/testthat/prod/fail/geo/eez-9700bc98.zip @@ -0,0 +1,5 @@ + + +Illegal property name: notvalidparameter for feature type MarineRegions:eez + + diff --git a/tests/testthat/prod/fail/geo/eez-f5f8f76d.zip b/tests/testthat/prod/fail/geo/eez-f5f8f76d.zip new file mode 100644 index 0000000..356b2f0 --- /dev/null +++ b/tests/testthat/prod/fail/geo/eez-f5f8f76d.zip @@ -0,0 +1,6 @@ + + +java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Integer +Cannot cast java.lang.String to java.lang.Integer + + diff --git a/tests/testthat/prod/fail/geo/ows-8fcb79.R b/tests/testthat/prod/fail/geo/ows-8fcb79.R new file mode 100644 index 0000000..368d7d5 --- /dev/null +++ b/tests/testthat/prod/fail/geo/ows-8fcb79.R @@ -0,0 +1,6 @@ +structure(list(method = "GET", url = "geo/ows?service=wfs&version=2.0.0&request=GetFeature&typeName=MarineRegions%3Aeez&cql_filter=mrgid%20%3D%20-1&outputFormat=SHAPE-ZIP", + status_code = 200L, headers = structure(list(`Access-Control-Allow-Origin` = "*", + `X-Frame-Options` = "SAMEORIGIN", `Content-Disposition` = "attachment; filename=eez.zip", + `Content-Type` = "application/zip", `Transfer-Encoding` = "chunked", + Date = "Wed, 26 Apr 2023 08:26:02 GMT"), class = "httr2_headers"), + body = as.raw(c(0x50, 0x4b, 0x03, 0x04, 0x14))), class = "httr2_response") diff --git a/tests/testthat/prod/fail/geo/ows-a366ca.R b/tests/testthat/prod/fail/geo/ows-a366ca.R index c540808..5721ba4 100644 --- a/tests/testthat/prod/fail/geo/ows-a366ca.R +++ b/tests/testthat/prod/fail/geo/ows-a366ca.R @@ -2,5 +2,5 @@ structure(list(method = "GET", url = "geo/ows?service=wfs&version=2.0.0&request= status_code = 400L, headers = structure(list(`Access-Control-Allow-Origin` = "*", `X-Frame-Options` = "SAMEORIGIN", `Content-Encoding` = "gzip", `Content-Type` = "application/xml", `Transfer-Encoding` = "chunked", - Date = "Mon, 24 Apr 2023 14:48:21 GMT"), class = "httr2_headers"), + Date = "Wed, 26 Apr 2023 08:25:25 GMT"), class = "httr2_headers"), body = charToRaw("\n\nIllegal property name: notvalidparameter for feature type MarineRegions:eez\n\n\n")), class = "httr2_response") diff --git a/tests/testthat/prod/fail/geo/ows-af137d.R b/tests/testthat/prod/fail/geo/ows-af137d.R index 61599ca..d9aeb18 100644 --- a/tests/testthat/prod/fail/geo/ows-af137d.R +++ b/tests/testthat/prod/fail/geo/ows-af137d.R @@ -2,5 +2,5 @@ structure(list(method = "GET", url = "geo/ows?service=wfs&version=2.0.0&request= status_code = 400L, headers = structure(list(`Access-Control-Allow-Origin` = "*", `X-Frame-Options` = "SAMEORIGIN", `Content-Encoding` = "gzip", `Content-Type` = "application/xml", `Transfer-Encoding` = "chunked", - Date = "Mon, 24 Apr 2023 14:48:21 GMT"), class = "httr2_headers"), + Date = "Wed, 26 Apr 2023 08:25:15 GMT"), class = "httr2_headers"), body = charToRaw("\n\norg.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 9; XML document structures must start and end within the same entity.\nXML document structures must start and end within the same entity.\n\n\n")), class = "httr2_response") diff --git a/tests/testthat/prod/fail/geo/ows-bf6baa.R b/tests/testthat/prod/fail/geo/ows-bf6baa.R index 073c768..b301725 100644 --- a/tests/testthat/prod/fail/geo/ows-bf6baa.R +++ b/tests/testthat/prod/fail/geo/ows-bf6baa.R @@ -2,5 +2,5 @@ structure(list(method = "GET", url = "geo/ows?service=wfs&version=2.0.0&request= status_code = 400L, headers = structure(list(`Access-Control-Allow-Origin` = "*", `X-Frame-Options` = "SAMEORIGIN", `Content-Encoding` = "gzip", `Content-Type` = "application/xml", `Transfer-Encoding` = "chunked", - Date = "Mon, 24 Apr 2023 14:48:22 GMT"), class = "httr2_headers"), + Date = "Wed, 26 Apr 2023 08:25:29 GMT"), class = "httr2_headers"), body = charToRaw("\n\njava.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Integer\nCannot cast java.lang.String to java.lang.Integer\n\n\n")), class = "httr2_response") diff --git a/tests/testthat/prod/fail/geo/ows-cfb5b6.R b/tests/testthat/prod/fail/geo/ows-cfb5b6.R index 1b22ce6..b086a68 100644 --- a/tests/testthat/prod/fail/geo/ows-cfb5b6.R +++ b/tests/testthat/prod/fail/geo/ows-cfb5b6.R @@ -2,5 +2,5 @@ structure(list(method = "GET", url = "geo/ows?service=wfs&version=2.0.0&request= status_code = 400L, headers = structure(list(`Access-Control-Allow-Origin` = "*", `X-Frame-Options` = "SAMEORIGIN", `Content-Encoding` = "gzip", `Content-Type` = "application/xml", `Transfer-Encoding` = "chunked", - Date = "Mon, 24 Apr 2023 14:48:21 GMT"), class = "httr2_headers"), + Date = "Wed, 26 Apr 2023 08:25:28 GMT"), class = "httr2_headers"), body = charToRaw("\n\nIllegal property name: notvalidparameter for feature type MarineRegions:eez\n\n\n")), class = "httr2_response") diff --git a/tests/testthat/prod/fail/geo/wfs-f93f5d.R b/tests/testthat/prod/fail/geo/wfs-f93f5d.R deleted file mode 100644 index 0bbe176..0000000 --- a/tests/testthat/prod/fail/geo/wfs-f93f5d.R +++ /dev/null @@ -1,21 +0,0 @@ -structure(list(url = "geo/wfs?request=GetCapabilities", status_code = 500L, - headers = structure(list(`access-control-allow-origin` = "*", - `x-frame-options` = "SAMEORIGIN", `cache-control` = "max-age=0, must-revalidate", - `content-disposition` = "inline; filename=geoserver-GetCapabilities.application", - `content-encoding` = "gzip", `content-type` = "application/xml", - `transfer-encoding` = "chunked", date = "Fri, 03 Feb 2023 15:33:09 GMT"), class = c("insensitive", - "list")), all_headers = list(list(status = 500L, version = "HTTP/1.1", - headers = structure(list(`access-control-allow-origin` = "*", - `x-frame-options` = "SAMEORIGIN", `cache-control` = "max-age=0, must-revalidate", - `content-disposition` = "inline; filename=geoserver-GetCapabilities.application", - `content-encoding` = "gzip", `content-type` = "application/xml", - `transfer-encoding` = "chunked", date = "Fri, 03 Feb 2023 15:33:09 GMT"), class = c("insensitive", - "list")))), cookies = structure(list(domain = logical(0), - flag = logical(0), path = logical(0), secure = logical(0), - expiration = structure(numeric(0), class = c("POSIXct", - "POSIXt")), name = logical(0), value = logical(0)), row.names = integer(0), class = "data.frame"), - content = charToRaw(""), - date = structure(1675438389, class = c("POSIXct", "POSIXt" - ), tzone = "GMT"), times = c(redirect = 0, namelookup = 0.002201, - connect = 0.028796, pretransfer = 0.065511, starttransfer = 0.112988, - total = 0.174872)), class = "response") diff --git a/tests/testthat/test-prod.R b/tests/testthat/test-prod.R index 72b6e10..e3b3ff0 100644 --- a/tests/testthat/test-prod.R +++ b/tests/testthat/test-prod.R @@ -201,6 +201,10 @@ test_that("mrp_get() assertions work", { httptest2::with_mock_dir("prod/fail/", { test_that("mrp_get: Bad filters errors surfaced", { + withr::local_options("mregions2.download_path" = "./prod/fail/geo") + withr::local_envvar("TESTPKG.ISTEST" = "true") + withr::local_envvar("TESTPKG.CACHETIME" = 0) + .f <- function() mrp_get("eez", filter="") expect_error(.f(), "XML getFeature request SAX parsing error") @@ -222,6 +226,17 @@ httptest2::with_mock_dir("prod/fail/", { expect_error(.f(), "NoApplicableCode") }) + + test_that("mrp_get: Warnings coming from the server are surfaced", { + withr::local_options("mregions2.download_path" = "./prod/fail/geo") + withr::local_envvar("TESTPKG.ISTEST" = "true") + withr::local_envvar("TESTPKG.CACHETIME" = 0) + + .f <- function() mrp_get("eez", cql_filter = "mrgid = -1") + expect_warning(.f(), regexp = "empty", fixed = TRUE) + }) + + }) httptest2::with_mock_dir("prod/ok/", { @@ -297,6 +312,7 @@ httptest2::with_mock_dir("prod/ok/", { test_that("mrp_get() works", { withr::local_options("mregions2.download_path" = "./prod/ok/geo") + withr::local_envvar("TESTPKG.ISTEST" = "true") expect_sf <- function(x){ expect_type(x, "list") @@ -306,8 +322,8 @@ httptest2::with_mock_dir("prod/ok/", { } - # Check without caching - withr::local_options("TESTPKG.CACHETIME" = 0) + # Mock HTTP request like if there was no cache + withr::local_envvar("TESTPKG.CACHETIME" = 0) # Mexican ECS Deposit .f1 <- function() mrp_get("ecs", cql_filter = "mrgid = 64123") @@ -319,8 +335,8 @@ httptest2::with_mock_dir("prod/ok/", { expect_sf(.f2()) expect_s3_class(sf::st_geometry(.f2()), "sfc_LINESTRING") - # Check with caching - withr::local_options("TESTPKG.CACHETIME" = Inf) + # Actually reading from cache without HTTP request + withr::local_envvar("TESTPKG.CACHETIME" = Inf) expect_message(.f1(), "Cache", fixed = TRUE) expect_sf(.f1())