tests/testthat/test-dbi-connection.R

test_that("show method prints only host if no user is defined", {
  con <- new("OdbcConnection")
  local_mocked_bindings(
    dbGetInfo = function(x) c(servername = "localhost", username = "", dbname = "", dbms.name = "", db.version = ""),
    dbIsValid = function(x) TRUE
  )

  expect_snapshot(con)
})

test_that("show method prints DISCONNECTED if not valid", {
  con <- new("OdbcConnection")
  local_mocked_bindings(
    dbGetInfo = function(x) c(servername = "localhost", username = "", dbname = "", dbms.name = "", db.version = ""),
    dbIsValid = function(x) FALSE
  )
  expect_snapshot(con)
})

test_that("show method does not print server if it is not available", {
  con <- new("OdbcConnection")
  local_mocked_bindings(
    dbGetInfo = function(x) c(servername = "", username = "", dbname = "", dbms.name = "", db.version = ""),
    dbIsValid = function(x) TRUE
  )
  expect_snapshot(con)
})

test_that("dbQuoteIdentifier() errors informatively", {
  con <- test_con("SQLITE")

  expect_snapshot(
    error = TRUE,
    dbQuoteIdentifier(con, NA_character_)
  )
})

Try the odbc package in your browser

Any scripts or data that you put into this service are public.

odbc documentation built on June 22, 2024, 9:47 a.m.