~hrbrmstr/sergeant

ref: 70a6bd9619a4234056af5898f804afa3514723dd sergeant/tests/testthat/test-dbitest.R -rw-r--r-- 1.5 KiB
70a6bd96boB Rudis fixed issue with 0-length query results 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
test_host <- Sys.getenv("DRILL_TEST_HOST", "localhost")

options(sergeant.bigint.warnonce = FALSE)

testthat::skip_on_cran()

expect_visible <- function(code) {
  ret <- withVisible(code)
  expect_true(ret$visible)
  ret$value
}

connect <- function (drv) {
  connect_call <- as.call(c(list(quote(dbConnect), drv)))
  connect_fun <- function() {}
  body(connect_fun) <- connect_call
  connect_fun()
}

context("r-lib dbi interface test")

dr <- Drill()

expect_s4_class(dr, "DBIDriver")
expect_is(dbGetInfo(dr), "list")
expect_true(all(names(dbGetInfo(dr)) %in% c("driver.version", "client.version")))

expect_equal(names(formals(dbConnect)), c("drv", "..."))
expect_equal(names(formals(dbDisconnect)), c("conn", "..."))

con <- expect_visible(connect(dr))
expect_s4_class(con, "DBIConnection")
expect_true(dbDisconnect(con))

expect_is(dbGetInfo(con), "list")

expect_is(format(con), "character")

expect_equal(names(formals(dbDataType)), c("dbObj", "obj", "..."))

expect_error(dbDataType(con, NULL))

expect_identical(dbDataType(con, letters), dbDataType(con, factor(letters)))
expect_identical(dbDataType(con, letters), dbDataType(con, ordered(letters)))

expect_true(
  all(c("db.version", "dbname", "username", "host", "port") %in% names(dbGetInfo(con)))
)

expect_false("password" %in% names(dbGetInfo(con)))

expect_equal(names(formals(dbListFields)), c("conn", "name", "..."))

fields <- dbListFields(con, "cp.`employee.json`")
expect_is(fields, "character")

expect_warning(dbListFields(con, "missing"))