File: test-gcs.R

package info (click to toggle)
r-cran-memoise 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 208 kB
  • sloc: sh: 10; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 774 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
context("gcs")

test_that("using a gcs cache works", {
  skip_on_cran()
  skip_on_travis_pr()
  skip_without_gcs_credentials()

  googleAuthR::gar_set_client(scopes = "https://www.googleapis.com/auth/cloud-platform")
  googleAuthR::gar_auth_service(Sys.getenv("GCS_AUTH_FILE"))

  aws <- cache_gcs("memoise-tests")
  i <- 0
  fn <- function() { i <<- i + 1; i }
  fnm <- memoise(fn, cache = aws)
  on.exit(forget(fnm))

  expect_equal(fn(), 1)
  expect_equal(fn(), 2)
  expect_equal(fnm(), 3)
  expect_equal(fnm(), 3)
  expect_equal(fn(), 4)
  expect_equal(fnm(), 3)

  expect_false(forget(fn))
  expect_true(forget(fnm))
  expect_equal(fnm(), 5)

  expect_true(drop_cache(fnm)())
  expect_equal(fnm(), 6)

  expect_true(is.memoised(fnm))
  expect_false(is.memoised(fn))
})