Skip to content
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

Merged
merged 13 commits into from
Dec 19, 2023
Merged

add helper to locate configuration files #680

merged 13 commits into from
Dec 19, 2023

Conversation

simonpcouch
Copy link
Collaborator

@simonpcouch simonpcouch commented Dec 14, 2023

Closes #565.☃️

@simonpcouch
Copy link
Collaborator Author

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


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")
Copy link
Collaborator Author

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.

@simonpcouch simonpcouch requested a review from hadley December 14, 2023 14:56
Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Member

@hadley hadley left a 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
Comment on lines 754 to 755
res <- strsplit(res, "\\:")
res <- vapply(res, `[[`, character(1), 2)
Copy link
Member

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().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

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.

Copy link
Member

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.

@simonpcouch
Copy link
Collaborator Author

Testing updates made in 275b69c. Muuuch better!

I believe 39fb93b is unrelated to this PR, but saw this output on devtools::test().

@hadley
Copy link
Member

hadley commented Dec 15, 2023

BTW I'm pretty sure lengths() is now old enough that we can use it

Also please hold of on merging this PR for a bit.

@hadley
Copy link
Member

hadley commented Dec 15, 2023

Good to go with the merge. My bad for the mix-up with the merge conflict 'cause of my file reorg PR

@simonpcouch
Copy link
Collaborator Author

All good! Glad we made that renaming happen.

simonpcouch and others added 4 commits December 15, 2023 10:42
`odbcListConfig()` now lives in `odbc-config.R`

Merge branch 'main' into odbcListConfig

# Conflicts:
#	NEWS.md
#	R/Connection.R
Copy link
Member

@hadley hadley left a 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.

})

test_that("odbcListConfig errors informatively without unixODBC", {
skip_on_os(c("windows", "solaris"))
Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

99938dd and e40215e should get us most of the way there, though I'm not sure how we'd mock through that first test where we do need odbcinst output.

@simonpcouch simonpcouch merged commit 6a8e295 into main Dec 19, 2023
16 checks passed
@simonpcouch simonpcouch deleted the odbcListConfig branch December 19, 2023 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve setup documentation
2 participants