Skip to content

Commit

Permalink
Add tests for other board types (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasilge authored Nov 14, 2023
1 parent 2a094b5 commit d8eb33a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/testthat/_snaps/write-plumber.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,44 @@
pr %>% vetiver_api(v)
}

# create plumber.R for complicated board

Code
cat(readr::read_lines(tmp), sep = "\n")
Output
# Generated by the vetiver package; edit with care
library(pins)
library(plumber)
library(rapidoc)
library(vetiver)
b <- board_s3(bucket = "foo", region = 6, endpoint = 8)
v <- vetiver_pin_read(b, "cars1")
#* @plumber
function(pr) {
pr %>% vetiver_api(v)
}

# create plumber.R for URL board

Code
cat(readr::read_lines(tmp), sep = "\n")
Output
# Generated by the vetiver package; edit with care
library(pins)
library(plumber)
library(rapidoc)
library(vetiver)
b <- board_url(c(foo = "foo", bar = "bar", baz = "baz"))
v <- vetiver_pin_read(b, "cars1")
#* @plumber
function(pr) {
pr %>% vetiver_api(v)
}

# create plumber.R with packages

Code
Expand Down
40 changes: 40 additions & 0 deletions tests/testthat/test-write-plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,46 @@ test_that("create plumber.R with no packages", {
)
})

test_that("create plumber.R for complicated board", {
skip_on_cran()
b <- pins::new_board(
"pins_board_s3",
api = 1L,
cache = board_cache_path("pins"),
versioned = FALSE,
bucket = "foo",
svc = list(.internal =
list(config = list(credentials = list(creds = list(profile = 4)),
region = 6, endpoint = 8)))
)
local_mocked_bindings(vetiver_pin_read = function(board, name, version) v)
tmp <- tempfile()
vetiver_write_plumber(b, "cars1", file = tmp)
expect_snapshot(
cat(readr::read_lines(tmp), sep = "\n"),
transform = redact_vetiver
)
})

test_that("create plumber.R for URL board", {
skip_on_cran()
b <- pins::new_board(
"pins_board_url",
api = 1L,
cache = board_cache_path("pins"),
versioned = FALSE,
bucket = "foo",
urls = c(foo = "foo", bar = "bar", baz = "baz")
)
local_mocked_bindings(vetiver_pin_read = function(board, name, version) v)
tmp <- tempfile()
vetiver_write_plumber(b, "cars1", file = tmp)
expect_snapshot(
cat(readr::read_lines(tmp), sep = "\n"),
transform = redact_vetiver
)
})

test_that("create plumber.R with packages", {
skip_on_cran()
b <- board_folder(path = tmp_dir)
Expand Down

0 comments on commit d8eb33a

Please sign in to comment.