Skip to content

Commit

Permalink
Adjust to PPPM API changes
Browse files Browse the repository at this point in the history
E.g. fix `repo_resolve()`. Closes #110.
  • Loading branch information
gaborcsardi committed Aug 8, 2024
1 parent 9f59411 commit 24cdb88
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
12 changes: 3 additions & 9 deletions R/repo-set.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 10 additions & 15 deletions tests/testthat/test-repo-set.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ 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
withr::local_envvar(PKGCACHE_PPM_URL = NA_character_)
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")
)
})

Expand Down Expand Up @@ -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")
)
})

Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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)
})
Expand Down

0 comments on commit 24cdb88

Please sign in to comment.