Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

DATA-8006 Use ZRAN #33

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@
^\.Rproj\.user$
README.Rmd
^.*.log
ci-rs.R
ci.sh
bootstrap.R
tests.dockerfile
^\.gitlab-ci\.yml$
21 changes: 21 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
image:
name: 996097627176.dkr.ecr.us-east-1.amazonaws.com/rstudio-worker
entrypoint: [""]

stages:
- test
- deploy

test:
stage: test
script:
- Rscript -e 'install.packages("rzapierci"); rzapierci::check_package(allowed_warnings = 3L)'

deploy:
stage: deploy
only:
- main
- master
- prod
script:
- Rscript -e 'install.packages("rzapierci"); rzapierci::deploy_package()'
25 changes: 0 additions & 25 deletions ci.sh

This file was deleted.

17 changes: 0 additions & 17 deletions tests.dockerfile

This file was deleted.

15 changes: 8 additions & 7 deletions tests/testthat/test_connection_to_redshift.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
context("Test that we can make a connection to Redshift")

zapieR::make_db_connections()

test_that(
"We can make a connection to Redshift",
expect_equal(
nrow(DBI::dbGetQuery(rs$con, "select * from event limit 1")),
1
)
"We can make a connection to Redshift", {
skip_on_ci()
zapieR::make_db_connections()
expect_equal(
nrow(DBI::dbGetQuery(rs$con, "select * from event limit 1")),
1
)
}
)
18 changes: 10 additions & 8 deletions tests/testthat/test_ctas.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ context("ctas()")

test_that(
"ctas works for temp table", {
ttn <- temp_table_name()
zapieR::rs_db("select 1 as foo") %>%
ctas(ttn, temp = TRUE)
expect_equivalent(zapieR::rs_db(ttn) %>%
skip_on_ci()
ttn <- temp_table_name()
zapieR::rs_db("select 1 as foo") %>%
ctas(ttn, temp = TRUE)
expect_equivalent(zapieR::rs_db(ttn) %>%
collect, data.frame(foo=1L))
DBI::dbExecute(zapieR::rs_db()$con, glue::glue("drop table {ttn}"))
})
DBI::dbExecute(zapieR::rs_db()$con, glue::glue("drop table {ttn}"))
})

test_that(
"ctas works for non-temp table", {
skip_on_ci()
ttn <- temp_table_name()
zapieR::rs_db("select 1 as foo") %>%
ctas(ttn, temp = FALSE)
Expand All @@ -22,6 +24,7 @@ test_that(

test_that(
"ctas works for view", {
skip_on_ci()
ttn <- temp_table_name()
ttvn <- temp_table_name()
zapieR::rs_db("select 1 as foo") %>%
Expand All @@ -36,9 +39,8 @@ test_that(

test_that(
"ctas works for in_schema", {
skip_on_ci()
zapieR::rs_db("select * from iris") %>%
ctas(dbplyr::in_schema("staging","redshiftToolsIris"), temp = FALSE)
expect_gte(zapieR::rs_db("Select count(*) as n from staging.redshiftToolsIris") %>% pull(n),1)
})


3 changes: 3 additions & 0 deletions tests/testthat/test_get_column_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ ttn <- temp_table_name()
on.exit(try(DBI::dbExecute(zapieR::rs_db()$con, glue::glue("DROP TABLE {ttn}"))), add = TRUE)

test_that("can get column names from empty & populated table", {
skip_on_ci()
rs_create_table(cars, zapieR::rs_db()$con, table_name = ttn)
expect_equivalent(get_column_names(con = zapieR::rs_db()$con, ttn), c("speed", "dist"))
rs_replace_table(data = cars, dbcon = zapieR::rs_db()$con, table_name = ttn, bucket = "zapier-data-science-storage")
expect_equivalent(suppressWarnings(get_column_names(con = zapieR::rs_db()$con, ttn)), c("speed", "dist"))
})

test_that("can get column names from populated table with schema", {
skip_on_ci()
rs_replace_table(data = cars, dbcon = zapieR::rs_db()$con, table_name = ttn, bucket = "zapier-data-science-storage")
expect_equivalent(get_column_names(con = zapieR::rs_db()$con, dbplyr::in_schema("public", ttn)), c("speed", "dist"))
})

test_that("can get column names from temp table", {
skip_on_ci()
ttn2 <- temp_table_name()
zapieR::rs_db(ttn) %>%
ctas(ttn2, temp = TRUE)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_redshift_utils.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
context("redshift-utils.R")

test_that("can decompose in_schema", {
skip_on_ci()
eg <- redshiftTools::decompose_in_schema(dbplyr::in_schema("s", "t"))
expect_equal(attr(eg, "table_name"), "t")
expect_equal(attr(eg, "schema_name"), "s")
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test_rs_upsert_table.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
context("rs_upsert_table()")

zapieR::make_db_connections()

test_that("We can insert a row into an existing table", {
skip_on_ci()
zapieR::make_db_connections()
test_table <- dbplyr::in_schema("staging","redshiftToolsIris")
test_table_char <- schema_to_character(test_table)
get_n <- function() {
Expand All @@ -14,12 +14,12 @@ test_that("We can insert a row into an existing table", {
})

## These tests are commented out because they are destructive
DBI::dbGetQuery(conn = rs$con, statement = "drop table if exists mtcars_with_id;")
mtcars_with_id <- cbind(id = 1:nrow(mtcars), mtcars)
rs_create_table(
.data = mtcars_with_id,
dbcon = rs$con, table_name = "mtcars_with_id"
)
# DBI::dbGetQuery(conn = rs$con, statement = "drop table if exists mtcars_with_id;")
# mtcars_with_id <- cbind(id = 1:nrow(mtcars), mtcars)
# rs_create_table(
# .data = mtcars_with_id,
# dbcon = rs$con, table_name = "mtcars_with_id"
# )

# test_that(
# "When the table exists but is empty, rs_upsert_table works", {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_spectrum_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ d1 <- cars
d1$moo <- lubridate::today()

test_that("Don't allow a partionless schema with type date", {
skip_on_ci()
expect_error(
create_external_table(con = rs$con, d = d1, table_name = dbplyr::in_schema("external_testing", "moo"), location = "nope")
)
Expand Down