|
| 1 | +context("Arrow IPC serializer") |
| 2 | + |
| 3 | +test_that("Arrow IPC serializes properly", { |
| 4 | + skip_if_not_installed("arrow") |
| 5 | + |
| 6 | + d <- data.frame(a=1, b=2, c="hi") |
| 7 | + val <- serializer_arrow_ipc_stream()(d, data.frame(), PlumberResponse$new(), stop) |
| 8 | + expect_equal(val$status, 200L) |
| 9 | + expect_equal(val$headers$`Content-Type`, "application/vnd.apache.arrow.stream") |
| 10 | + |
| 11 | + # can test by doing a full round trip if we believe the parser works via `test-parse-body.R` |
| 12 | + parsed <- parse_body(val$body, "application/vnd.apache.arrow.stream", make_parser("arrow_ipc_stream")) |
| 13 | + # convert from feather tibble to data.frame |
| 14 | + parsed <- as.data.frame(parsed, stringsAsFactors = FALSE) |
| 15 | + attr(parsed, "spec") <- NULL |
| 16 | + |
| 17 | + expect_equal(parsed, d) |
| 18 | +}) |
| 19 | + |
| 20 | +test_that("Errors call error handler", { |
| 21 | + skip_if_not_installed("arrow") |
| 22 | + |
| 23 | + errors <- 0 |
| 24 | + errHandler <- function(req, res, err){ |
| 25 | + errors <<- errors + 1 |
| 26 | + } |
| 27 | + |
| 28 | + expect_equal(errors, 0) |
| 29 | + serializer_feather()(parse(text="hi"), data.frame(), PlumberResponse$new("csv"), errorHandler = errHandler) |
| 30 | + expect_equal(errors, 1) |
| 31 | +}) |
| 32 | + |
| 33 | +test_that("Errors are rendered correctly with debug TRUE", { |
| 34 | + skip_if_not_installed("arrow") |
| 35 | + |
| 36 | + pr <- pr() %>% pr_get("/", function() stop("myerror"), serializer = serializer_feather()) %>% pr_set_debug(TRUE) |
| 37 | + capture.output(res <- pr$serve(make_req(pr = pr), PlumberResponse$new("csv"))) |
| 38 | + |
| 39 | + expect_match(res$body, "Error in (function () : myerror", fixed = TRUE) |
| 40 | +}) |
| 41 | + |
0 commit comments