Skip to content

Commit

Permalink
test on duckdb on github
Browse files Browse the repository at this point in the history
  • Loading branch information
ablack3 committed Dec 9, 2023
1 parent abe0de2 commit 1ee48e0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/duckdb-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: Postgres-test

jobs:
R-CMD-check:
if: github.repository == 'darwin-eu/CDMConnector' || github.repository == 'darwin-eu-dev/CDMConnector'
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: true
matrix:
config:
- {os: macOS-latest, r: 'release'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name: Install suggested packages
run: |
install.packages("DatabaseConnector")
install.packages("RPostgres")
install.packages("testthat")
shell: Rscript {0}

- name: Install CirceR
run: |
install.packages("rJava")
install.packages("RJSONIO")
install.packages("CirceR", repos = "https://OHDSI.github.io/drat", type = "source")
install.packages("Capr", repos = "https://OHDSI.github.io/drat", type = "source")
shell: Rscript {0}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
dependencies: '"hard"'
extra-packages: any::rcmdcheck
needs: check

- name: Run tests on duckdb
run: |
withr::with_envvar(new = c("CI_TEST_DB" = "duckdb"), testthat::test_local())
shell: Rscript {0}


6 changes: 4 additions & 2 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ get_cdm_schema <- function(dbms) {
return(s)
}

get_write_schema <- function(dbms, prefix = NULL) {
get_write_schema <- function(dbms, prefix = paste0("temp", as.integer(Sys.time()) %% 10000L, "_")) {
s <- switch (dbms,
"postgres" = Sys.getenv("CDM5_POSTGRESQL_SCRATCH_SCHEMA"),
"local" = Sys.getenv("LOCAL_POSTGRESQL_SCRATCH_SCHEMA"),
Expand Down Expand Up @@ -158,5 +158,7 @@ if (Sys.getenv("CI_TEST_DB") == "") {
checkmate::assert_choice(Sys.getenv("CI_TEST_DB"),
choices = c("duckdb", "postgres", "sqlserver", "redshift"))
dbToTest <- Sys.getenv("CI_TEST_DB")
print(paste("running tests. on ", dbToTest))
print(paste("running CI tests on ", dbToTest))
}


22 changes: 12 additions & 10 deletions tests/testthat/test-db-cohort_ddl.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
test_cohort_ddl <- function(con, write_schema) {
skip_if_not("prefix" %in% names(write_schema))
name <- "testcohort"

expect_no_error(
createCohortTables(con,
writeSchema = write_schema,
name = "testcohort",
name = name,
computeAttrition = FALSE)
)

tables <- sort(list_tables(con, schema = write_schema))

# cleanup ...
# tables_to_drop <- tables %>% stringr::str_subset("TEST")
# purrr::walk(tables_to_drop, ~DBI::dbRemoveTable(con, inSchema(write_schema , .)))

name <- paste0(tidyr::replace_na(write_schema["prefix"], ""), "testcohort")

if (dbms(con) %in% c("oracle", "snowflake")) {
name <- toupper(name)
}

expect_true(name %in% tables)

if ("prefix" %in% names(write_schema)) {
write_schema <- unname(write_schema[names(write_schema) != "prefix"])
tables_to_drop <- stringr::str_subset(tables, name)

for (tb in tables_to_drop) {
DBI::dbRemoveTable(con, inSchema(write_schema, tb, dbms = dbms(con)))
}

DBI::dbRemoveTable(con, inSchema(write_schema, name, dbms = dbms(con)))
tables <- list_tables(con, schema = write_schema)
for (tb in tables_to_drop) {
expect_false(tb %in% tables)
}
}

for (dbtype in dbToTest) {
Expand Down

0 comments on commit 1ee48e0

Please sign in to comment.