-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add helper to locate configuration files #680
Conversation
On my machine: library(odbc)
odbcListConfig()
#> name location
#> 1 DRIVERS /opt/homebrew/etc/odbcinst.ini
#> 2 SYSTEM DATA SOURCES /opt/homebrew/etc/odbc.ini
#> 3 USER DATA SOURCES /Users/simoncouch/.odbc.ini Created on 2023-12-14 with reprex v2.0.2 |
tests/testthat/test-Connection.R
Outdated
|
||
test_that("odbcListConfig errors informatively when unixODBC isn't available", { | ||
skip_on_os(c("windows", "solaris")) | ||
skip_if(!identical(unname(Sys.which("odbcinst")), ""), "odbcinst is available") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this test will ever be run on our CI as currently configured. Ran on a fresh RStudio Pro instance and checks were fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Just a couple of last thoughts about testing this code; let me know if you haven't used local_mocked_bindings()
before and I can give you some pointers.
R/Connection.R
Outdated
res <- strsplit(res, "\\:") | ||
res <- vapply(res, `[[`, character(1), 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth considering a quick check of the output here, maybe something like this:
if (!identical(length(res), c(2, 2, 2)) {
abort("Failed to parse output from odbcinst", internal = TRUE)
}
That'll ensure the user gets a reasonable error if odbcinst
gives unexpected results. (And the internal = TRUE
ensures they get a prompt to file an issue).
Then you can add a snapshot test for that error by mocking system()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only question here is whether we should run a similar check instead on the output of system("odbcinst -j", intern = TRUE)
? Based on it's source code I'm skeptical that odbcinst will ever return something that's almost parsable for us, but some issue in the communication with system()
seems plausible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's worth spending too much more time contemplating this as it's an unlikely failure mode; we just want to make sure we get something diagnostic in the unlikely event that the output does change.
BTW I'm pretty sure Also please hold of on merging this PR for a bit. |
Good to go with the merge. My bad for the mix-up with the merge conflict 'cause of my file reorg PR |
All good! Glad we made that renaming happen. |
`odbcListConfig()` now lives in `odbc-config.R` Merge branch 'main' into odbcListConfig # Conflicts: # NEWS.md # R/Connection.R
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two tiny last testing things; they're not really important in and of themselves but I think they're good habits to build going forward.
tests/testthat/test-odbc-config.R
Outdated
}) | ||
|
||
test_that("odbcListConfig errors informatively without unixODBC", { | ||
skip_on_os(c("windows", "solaris")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I'd be tempted to make a is_window()
function so that you could mock it and then drop the skips.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing. In these tests I always skip on Solaris. Should is_windows()
on Solaris return true? Or figure out how to support Solaris and test on those systems as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once you've mocked the right functions, it shouldn't matter which OS it's actually running on.
And I'm reasonably certain we don't generally need to worry about solaris any more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #565.☃️