Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sentryR
Type: Package
Title: Send Errors and Messages to Sentry
Title: Send Errors and Messages to 'Sentry'
Version: 1.0.0
Authors@R: c(
person("Joao", "Santiago", email = "[email protected]", role = c("aut", "cre")),
Expand All @@ -14,7 +14,7 @@ LazyData: true
ByteCompile: true
URL: https://github.com/ozean12/sentryR
BugReports: https://github.com/ozean12/sentryR/issues
RoxygenNote: 7.0.1
RoxygenNote: 7.0.2
Imports:
httr,
jsonlite,
Expand All @@ -26,4 +26,5 @@ Suggests:
covr,
httptest,
mockery,
testthat (>= 2.1.0)
testthat (>= 2.1.0),
plumber
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# pre-calculates a couple of re-used values
# plays well with the glue package too
.sentry_env <- new.env()

# FIXME: should use utils::packageVersion() instead, but that's not working
# with CRAN because the package is checked before being installed, thus there is
# no sentryR package to get the version from
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/helper-mocks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# mock request
# From the plumber tests
# https://github.com/rstudio/plumber/blob/master/tests/testthat/helper-mock-request.R
make_req <- function(verb, path, qs = "", body = "") {
req <- new.env()
req$REQUEST_METHOD <- toupper(verb)
req$PATH_INFO <- path
req$QUERY_STRING <- qs
req$rook.input <- list(read_lines = function() {
body
})
req
}
1 change: 0 additions & 1 deletion tests/testthat/helper.R

This file was deleted.

27 changes: 0 additions & 27 deletions tests/testthat/mocks.R

This file was deleted.

17 changes: 12 additions & 5 deletions tests/testthat/test-sentry.R → tests/testthat/test-core.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test-sentry")
context("test-sentry-core")

test_that("parsing the dsn works", {
expect_error(parse_dsn(888))
Expand Down Expand Up @@ -41,9 +41,11 @@ test_that("setting configuration works", {
expect_error(configure_sentry(42))
expect_error(configure_sentry(c("https://[email protected]/1", "https://[email protected]/2")))

configure_sentry(dsn = "https://[email protected]/1",
app_name = "el appo", app_version = "8.8.8",
environment = "production")
configure_sentry(
dsn = "https://[email protected]/1",
app_name = "el appo", app_version = "8.8.8",
environment = "production"
)

expect_equal(.sentry_env$payload_skeleton$contexts$app$app_name, "el appo")
expect_equal(.sentry_env$payload_skeleton$contexts$app$app_version, "8.8.8")
Expand All @@ -57,7 +59,6 @@ test_that("setting configuration works", {
expect_equal(.sentry_env$project_id, "1")

rm(list = ls(envir = .sentry_env), envir = .sentry_env)

})

test_that("builds payload correctly", {
Expand Down Expand Up @@ -119,6 +120,12 @@ test_that("we build the correct sentry.io call url", {
})

test_that("we build the correct headers", {

# No configuration yet
expect_error(
sentry_headers()
)

# without deprecated secret key
.sentry_env$public_key <- "1234"
.sentry_env$secret_key <- NA
Expand Down
48 changes: 48 additions & 0 deletions tests/testthat/test-plumber_handlers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
context("test handlers")

test_that("default_error_handler works", {
mock_req <- make_req("angel_attack", "/launch_eva01",
body = '[{"battery_level": "5 min"}]'
)
mock_res <- plumber:::PlumberResponse$new()
handled <- default_error_handler(mock_req, mock_res, simpleError("NO! NO! NO!"))

expect_true(
is.list(handled)
)
expect_equal(
names(handled), c("error")
)
expect_equal(
handled$error, "500 - Internal server error"
)
expect_equal(
mock_res$status, 500
)

options(plumber.debug = TRUE)
mock_res$status <- 200
handled <- default_error_handler(mock_req, mock_res, simpleError("NO! NO! NO!"))

expect_equal(
names(handled), c("error", "message")
)
expect_equal(
handled$error, "500 - Internal server error"
)
expect_equal(
handled$message, "Error: NO! NO! NO!\n"
)

# Now with status already set to 500
handled <- default_error_handler(mock_req, mock_res, simpleError("NO! NO! NO!"))
expect_equal(
handled$error, "Internal error"
)
})

test_that("we can wrap error handlers with sentry", {
wrapped <- wrap_error_handler_with_sentry()

expect_true(is.function(wrapped))
})