Skip to content

Commit

Permalink
Change approach for downloading JDBC drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena committed Dec 14, 2023
1 parent 404c919 commit 31e9d9b
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@ withr::defer(
testthat::teardown_env()
)

if (dir.exists(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"))) {
jdbcDriverFolder <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER")
} else {
jdbcDriverFolder <- "~/.jdbcDrivers"
dir.create(jdbcDriverFolder, showWarnings = FALSE)
baseDatabaseConnectorJarFolder <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER")
Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = jdbcDriverFolder)
withr::defer(
{
unlink(jdbcDriverFolder, recursive = TRUE, force = TRUE)
Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = baseDatabaseConnectorJarFolder)
if (Sys.getenv("DONT_DOWNLOAD_JDBC_DRIVERS", "") != "TRUE") {
oldJarFolder <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER")
Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = tempfile("jdbcDrivers"))
dir.create(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"))

if (testthat::is_testing()) {
withr::defer({
unlink(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"), recursive = TRUE, force = TRUE)
Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = oldJarFolder)
},
testthat::teardown_env()
)
)
}
}


# Create a unique ID for the table identifiers
tableSuffix <- paste0(substr(.Platform$OS.type, 1, 3), format(Sys.time(), "%y%m%d%H%M%S"), sample(1:100, 1))
tableSuffix <- abs(digest::digest2int(tableSuffix))
Expand Down

0 comments on commit 31e9d9b

Please sign in to comment.