Skip to content

Commit

Permalink
Add skip_on_cran to db tests (#167)
Browse files Browse the repository at this point in the history
* Add skip_on_cran to db tests

* Fix typo in NEWS.md

* Replace skip_on_cran with custom skip_on_runiverse
  • Loading branch information
brancengregory authored May 24, 2024
1 parent 08b9163 commit 3d26395
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
## Bug Fixes
- Fixed bugs in `ojo_auth()` which prevented it from successfully backing up the `.Renviron` file.

## Package Maintanance
## Package Maintenance
- Changed from Base R file paths to the `{fs}` package.
- Adjusted GitHub Actions workflows to not run on draft PRs.
- Added spellcheck GitHub Actions.
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/helper-runiverse.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Shoutout to https://github.com/mhpob/matos/
skip_on_runiverse <- function() {
skip_if(
Sys.getenv("MY_UNIVERSE", "") != "",
"On R-universe."
)
}
2 changes: 2 additions & 0 deletions tests/testthat/test-ojo_civ_cases.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("ojo_civ_cases works", {
skip_on_runiverse()

testthat::expect_no_error({
ojo_civ_cases()
})
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-ojo_collect.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("ojo_collect works in interactive mode", {
skip_on_runiverse()

expect_no_error({
ojo_tbl("case") |>
head(1) |>
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-ojo_connect.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("ojo_connect creates a new connection", {
skip_on_runiverse()

con <- ojo_connect()
expect_true(DBI::dbIsValid(con), "Connection should be valid")

Expand All @@ -7,7 +9,7 @@ test_that("ojo_connect creates a new connection", {
})

test_that("ojo_connect reuses existing connection", {
skip_on_cran()
skip_on_runiverse()

con1 <- ojo_connect()
con2 <- ojo_connect()
Expand All @@ -20,7 +22,7 @@ test_that("ojo_connect reuses existing connection", {
})

test_that("ojo_connect handles connection pooling correctly", {
skip_on_cran()
skip_on_runiverse()

pool_con <- ojo_connect(.pool = TRUE)
expect_true(DBI::dbIsValid(pool_con), "Pooled connection should be valid")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-ojo_crim_cases.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("ojo_crim_cases works", {
skip_on_runiverse()

testthat::expect_no_error({
ojo_crim_cases()
})
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-ojo_list_schemas.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("ojo_list_schemas hasn't changed", {
skip_on_runiverse()

expect_snapshot_value(
ojo_list_schemas(),
style = "deparse"
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-ojo_list_tables.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("ojo_list_tables hasn't changed", {
skip_on_runiverse()

expect_snapshot_value(
ojo_list_tables("public"),
style = "deparse"
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-ojo_list_vars.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("ojo_list_vars hasn't changed", {
skip_on_runiverse()

expect_snapshot_value(
ojo_list_vars("case"),
style = "deparse"
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-ojo_query.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("ojo_query executes SQL and returns a tibble", {
skip_on_runiverse()

# A simple, safe query that assumes the existence of a 'case' table
query <- 'SELECT * FROM "case" LIMIT 10'

Expand All @@ -15,6 +17,8 @@ test_that("ojo_query executes SQL and returns a tibble", {

# Test error handling for malformed queries
test_that("ojo_query handles SQL errors", {
skip_on_runiverse()

# Intentionally malformed SQL query
bad_query <- "SELEC * FROM nonexistent_table"

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-ojo_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test_that("ojo_tbl handles non-existent tables correctly", {
})

test_that("ojo_tbl's can join", {
skip_on_runiverse()

tbl <- ojo_tbl("case")
tbl2 <- ojo_tbl("minute")

Expand Down

0 comments on commit 3d26395

Please sign in to comment.