Skip to content

Commit

Permalink
Add testing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Cook committed May 25, 2017
1 parent 2af013a commit addad44
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Imports:
Suggests:
odbc,
RJDBC,
nycflights13
nycflights13,
testthat
SystemRequirements: Impala driver to support a 'DBI'-compatible R interface
NeedsCompilation: no
License: Apache License 2.0 | file LICENSE
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(implyr)

test_check("implyr")
40 changes: 40 additions & 0 deletions tests/testthat/helper-src.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
library(RJDBC)
library(nycflights13)

java_home <- Sys.getenv("JAVA_HOME", unset = NA)
jdbc_url <- Sys.getenv("IMPLYR_TEST_JDBC", unset = NA)
jdbc_host <- Sys.getenv("IMPLYR_TEST_HOST", unset = NA)
jdbc_port <- Sys.getenv("IMPLYR_TEST_PORT", unset = NA)
jdbc_user <- Sys.getenv("IMPLYR_TEST_USER", unset = NA)
jdbc_pass <- Sys.getenv("IMPLYR_TEST_PASS", unset = NA)

run_tests <- FALSE
if (!is.na(java_home) & !is.na(jdbc_url) & !is.na(jdbc_host) &
!is.na(jdbc_port) & !is.na(jdbc_user) & !is.na(jdbc_pass)) {
jdbc_path <- tempdir()
jdbc_zip <- file.path(jdbc_path, basename(jdbc_url))
unlink(jdbc_zip)
download.file(jdbc_url, jdbc_zip)
jdbc_jars <- tools::file_path_sans_ext(jdbc_zip)
unlink(jdbc_jars, recursive = TRUE)
dir.create(jdbc_jars)
unzip(jdbc_zip, exdir = jdbc_jars)
impala_classpath <- list.files(path = jdbc_jars, pattern = "\\.jar$", full.names = TRUE)
rJava::.jinit(classpath = impala_classpath)
drv <- RJDBC::JDBC("com.cloudera.impala.jdbc41.Driver", impala_classpath, "`")
jdbc_conn_str <- paste0("jdbc:impala://", jdbc_host, ":", jdbc_port)
impala <- implyr::src_impala(drv, jdbc_conn_str, jdbc_user, jdbc_pass)
run_tests <- TRUE
}

check_impala <- function() {
if (!run_tests) {
skip("This environment not configured for tests")
}
}

disconnect <- function() {
if (run_tests) {
dbDisconnect(impala)
}
}
9 changes: 9 additions & 0 deletions tests/testthat/test-basic.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
context("basic tests")

test_that("tbl_impala matches tbl_df", {
check_impala()
test_op <- function(x) {
x %>% arrange(carrier) %>% collect()
}
compare_tbls(list(tbl(impala, "airlines"), nycflights13::airlines), op = test_op)
})
1 change: 1 addition & 0 deletions tests/testthat/zzz-disconnect.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disconnect()

0 comments on commit addad44

Please sign in to comment.