tests/testthat/test-serializer-octet.R

test_that("octet serializes raw objects properly", {

  content <- charToRaw("Beware of bugs in the above code; I have only proved it correct, not tried it.")

  val <- serializer_octet()(content, list(), PlumberResponse$new(), stop)
  expect_equal(val$status, 200L)
  expect_equal(val$headers$`Content-Type`, "application/octet-stream")
  expect_equal(val$body, content)
  expect_equal(rawToChar(val$body), rawToChar(content))
})

test_that("octet throws on non-raw objects", {

  content <- "Beware of bugs in the above code; I have only proved it correct, not tried it."

  expect_error(
    serializer_octet()(
      content,
      list(),
      PlumberResponse$new(),
      function(req, res, err) stop(err)
    ),
    "received non-raw data",
  )
})

Try the plumber package in your browser

Any scripts or data that you put into this service are public.

plumber documentation built on Sept. 7, 2022, 1:05 a.m.