From 24cdb888c565b1d9fa4e368316479bba8f56239c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Thu, 8 Aug 2024 10:35:19 +0200 Subject: [PATCH] Adjust to PPPM API changes E.g. fix `repo_resolve()`. Closes #110. --- R/repo-set.R | 12 +++--------- tests/testthat/test-repo-set.R | 25 ++++++++++--------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/R/repo-set.R b/R/repo-set.R index c21ef6f9..3874d114 100644 --- a/R/repo-set.R +++ b/R/repo-set.R @@ -239,16 +239,10 @@ repo_sugar_ppm <- function(x, nm) { if (as.character(date) == "latest") { ver <- "latest" } else { - vers <- pkgenv$ppm_versions - ppm_dates <- names(vers) - if (date < ppm_dates[1]) { - stop("PPM snapshots go back to ", as.Date(ppm_dates[1]), " only") + if (date < "2017-10-10") { + stop("PPM snapshots go back to 2017-10-10 only") } - sel <- which(date <= ppm_dates)[1] - if (is.na(sel)) { - stop("Cannot find matching PPM snapshot for ", date) - } - ver <- vers[[sel]] + ver <- as.character(date) } # create repo URL diff --git a/tests/testthat/test-repo-set.R b/tests/testthat/test-repo-set.R index a6adfafd..6c26e214 100644 --- a/tests/testthat/test-repo-set.R +++ b/tests/testthat/test-repo-set.R @@ -41,11 +41,11 @@ test_that("repo_resolve", { ) expect_equal( repo_resolve("PPM@2021-02-04"), - c(CRAN = "https://packagemanager.posit.co/cran/1175516") + c(CRAN = "https://packagemanager.posit.co/cran/2021-02-04") ) expect_equal( repo_resolve("PPM@2021-02-04T14:33:56"), - c(CRAN = "https://packagemanager.posit.co/cran/1175516") + c(CRAN = "https://packagemanager.posit.co/cran/2021-02-04") ) # RSPM @@ -53,11 +53,11 @@ test_that("repo_resolve", { withr::local_envvar(PKGCACHE_PPM_BINARIES = "false") expect_equal( repo_resolve("RSPM@2021-02-04"), - c(CRAN = "https://packagemanager.posit.co/cran/1175516") + c(CRAN = "https://packagemanager.posit.co/cran/2021-02-04") ) expect_equal( repo_resolve("RSPM@2021-02-04T14:33:56"), - c(CRAN = "https://packagemanager.posit.co/cran/1175516") + c(CRAN = "https://packagemanager.posit.co/cran/2021-02-04") ) }) @@ -88,13 +88,13 @@ test_that("repo_resolve with PPM", { mockery::stub(repo_sugar_ppm, "getRversion", "4.2.2") expect_equal( repo_sugar_ppm("PPM@2021-01-26", nm = NULL), - c(CRAN = "https://packagemanager.posit.co/cran/__linux__/jammy/1014755") + c(CRAN = "https://packagemanager.posit.co/cran/__linux__/jammy/2021-01-26") ) mockery::stub(repo_sugar_ppm, "getRversion", "1.0.0") expect_equal( repo_sugar_ppm("PPM@2021-01-26", nm = NULL), - c(CRAN = "https://packagemanager.posit.co/cran/1014755") + c(CRAN = "https://packagemanager.posit.co/cran/2021-01-26") ) }) @@ -172,7 +172,7 @@ test_that("repo_sugar_ppm", { withr::local_options(repos = NULL) expect_equal( repo_sugar_ppm("2021-02-04", NULL), - c(CRAN = "https://packagemanager.posit.co/cran/1175516") + c(CRAN = "https://packagemanager.posit.co/cran/2021-02-04") ) withr::local_envvar( @@ -181,7 +181,7 @@ test_that("repo_sugar_ppm", { ) expect_equal( repo_sugar_ppm("2021-02-04", NULL), - c(CRAN = "https://my.ppm/repo/1175516") + c(CRAN = "https://my.ppm/repo/2021-02-04") ) called <- FALSE @@ -191,13 +191,8 @@ test_that("repo_sugar_ppm", { }) expect_error( - repo_sugar_ppm(as.Date(names(pkgenv$ppm_versions)[1]) - 1, NULL), - "PPM snapshots go back to" - ) - - expect_error( - repo_sugar_ppm(as.Date(last(names(pkgenv$ppm_versions))) + 1, NULL), - "Cannot find matching PPM snapshot for" + repo_sugar_ppm(as.Date("2017-10-01"), NULL), + "PPM snapshots go back to 2017-10-10" ) expect_true(called) })