Skip to content

Commit

Permalink
Replace more instances of CALYPSO with OMOPCAT (#73)
Browse files Browse the repository at this point in the history
* Replace more instances of `CALYPSO` with `OMOPCAT`

Apparently missed the environment variables last time

* Add test for `.check_env()`
  • Loading branch information
milanmlft authored Sep 25, 2024
1 parent aead0b4 commit 3575188
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/run_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ run_app <- function(
}

.check_env <- function() {
required <- "CALYPSO_DATA_PATH"
required <- "OMOPCAT_DATA_PATH"
missing <- required[!required %in% names(Sys.getenv())]
if (length(missing) > 0) {
cli::cli_abort("The following environment variables are missing: {.envvar {missing}}")
Expand Down
8 changes: 4 additions & 4 deletions R/utils_get_data.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' Should we be using the inst/dev_data?
#'
#' Only if we are running as a development server and CALYPSO_DATA_PATH
#' Only if we are running as a development server and OMOPCAT_DATA_PATH
#' is not set.
#'
#' @noRd
should_use_dev_data <- function() {
golem::app_dev() && Sys.getenv("CALYPSO_DATA_PATH") == ""
golem::app_dev() && Sys.getenv("OMOPCAT_DATA_PATH") == ""
}


Expand Down Expand Up @@ -48,9 +48,9 @@ get_summary_stats <- function() {
}

.read_parquet_table <- function(table_name) {
data_dir <- Sys.getenv("CALYPSO_DATA_PATH")
data_dir <- Sys.getenv("OMOPCAT_DATA_PATH")
if (data_dir == "") {
cli::cli_abort("Environment variable {.envvar CALYPSO_DATA_PATH} not set")
cli::cli_abort("Environment variable {.envvar OMOPCAT_DATA_PATH} not set")
}
if (!dir.exists(data_dir)) {
cli::cli_abort("Data directory {.file {data_dir}} not found")
Expand Down
2 changes: 1 addition & 1 deletion deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
HTTP_PROXY: ${HTTP_PROXY}
HTTPS_PROXY: ${HTTPS_PROXY}
GOLEM_CONFIG_ACTIVE: production
CALYPSO_DATA_PATH: /etc/omopcat/data
OMOPCAT_DATA_PATH: /etc/omopcat/data
LOW_FREQUENCY_THRESHOLD: 5
LOW_FREQUENCY_REPLACEMENT: 2.5
volumes:
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-run_app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_that("Env check fails when envvars missing", {
withr::local_envvar(OMOPCAT_DATA_PATH = NULL)
expect_error(.check_env(), "The following environment variables are missing: `OMOPCAT_DATA_PATH`")
})
10 changes: 5 additions & 5 deletions tests/testthat/test-utils_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ test_that("Dev data files are consistent", {
})

test_that("Data getters fail in production if envvar not set", {
withr::local_envvar(GOLEM_CONFIG_ACTIVE = "production", CALYPSO_DATA_PATH = NA)
withr::local_envvar(GOLEM_CONFIG_ACTIVE = "production", OMOPCAT_DATA_PATH = NA)
withr::local_options(list("golem.app.prod" = TRUE))

expect_true(golem::app_prod())
expect_error(get_concepts_table(), "Environment variable `CALYPSO_DATA_PATH` not set")
expect_error(get_monthly_counts(), "Environment variable `CALYPSO_DATA_PATH` not set")
expect_error(get_summary_stats(), "Environment variable `CALYPSO_DATA_PATH` not set")
expect_error(get_concepts_table(), "Environment variable `OMOPCAT_DATA_PATH` not set")
expect_error(get_monthly_counts(), "Environment variable `OMOPCAT_DATA_PATH` not set")
expect_error(get_summary_stats(), "Environment variable `OMOPCAT_DATA_PATH` not set")
})

test_that("Data getters fail in production if data directory does not exist", {
withr::local_envvar(c(
"GOLEM_CONFIG_ACTIVE" = "production",
"CALYPSO_DATA_PATH" = "/i/dont/exist"
"OMOPCAT_DATA_PATH" = "/i/dont/exist"
))
withr::local_options(list("golem.app.prod" = TRUE))

Expand Down

0 comments on commit 3575188

Please sign in to comment.