Skip to content

Commit

Permalink
improve error handling on database connector jar setings.
Browse files Browse the repository at this point in the history
  • Loading branch information
fdefalco committed Sep 7, 2023
1 parent 1bcb223 commit 428420e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
27 changes: 25 additions & 2 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
# Specify desired test platforms
cdmVersion <- "5.4"
testDatabases <- c("postgresql")

# Download the JDBC drivers used in the tests
library(DatabaseConnector)

if (is.na(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"))) {
missingJarFolderEnvironmentVariable <- FALSE
emptyJarFolderEnivornmentVariable <- FALSE
jarFolderDoesNotExist <- FALSE

missingJarFolderEnvironmentVariable <- is.na(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"))
if (missingJarFolderEnvironmentVariable) {
cat("DATABASECONNECTOR_JAR_FOLDER environment variable not set.")
} else {
emptyJarFolderEnivornmentVariable <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER")==""
if (emptyJarFolderEnivornmentVariable) {
cat("DATABASECONNECTOR_JAR_FOLDER environment variable is empty string")
} else {
jarFolderDoesNotExist <- !dir.exists(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"))
if (jarFolderDoesNotExist) {
cat(paste("specified DATABASECONNECTOR_JAR_FOLDER", Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"), "does not exist."))
}
}
}

if ( missingJarFolderEnvironmentVariable| emptyJarFolderEnivornmentVariable | jarFolderDoesNotExist) {
driverPath <- tempdir()
cat("\ndownloading drivers\n")
downloadJdbcDrivers("redshift", pathToDriver = driverPath)
Expand All @@ -12,7 +35,7 @@ if (is.na(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"))) {
driverPath <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER")
}

# Helper functions used in tests -----------------------------------------------
# Helper functions used in tests
getConnectionDetails <- function(dbms) {
switch (dbms,
"postgresql" = createConnectionDetails(
Expand Down
7 changes: 0 additions & 7 deletions tests/testthat/test-executeDdl.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# To run tests for one dbms and one cdmVersion use the variables below
dbms <- "postgresql"
cdmVersion <- "5.4"
testDatabases <- c(dbms)

# testDatabases <- c("oracle", "postgresql", "sql server", "redshift")
# testDatabases <- c("redshift")

test_that("getConnectionDetails works", {
for(dbms in testDatabases) {
Expand Down

0 comments on commit 428420e

Please sign in to comment.