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

mock writing to disk #57

Closed
sckott opened this issue Jan 15, 2019 · 0 comments · Fixed by #76
Closed

mock writing to disk #57

sckott opened this issue Jan 15, 2019 · 0 comments · Fixed by #76
Milestone

Comments

@sckott
Copy link
Collaborator

sckott commented Jan 15, 2019

Info

for each of curl, crul, httr

via curl::curl_fetch_disk() for curl, disk = TRUE for crul and httr::write_disk() for httr

the latter two build on top of the first.

for each of these, if the user writes to disk, the $content slot is:

  • character class
  • the path to the file

rather than what $content normally is: class raw


Approach

  • if to_return() not specified, then all is good, nothing different from normal, $content is length 0
  • if body in to_return() IS specified, user must give a connection object with a file path that alraedy exists (avoid allowing a file path as a string so we don't have to worry about strings. vs. files)

e.g.

(f <- tempfile())
#> "/var/folders/fc/n7g_vrvn0sx_st0p8lxb3ts40000gn/T//Rtmp1f2UTM/filec69b5e600215"
stub_request("get", "https://httpbin.org/get") %>% 
  to_return(body = file(f))
out <- curl_fetch_disk("https://httpbin.org/get", tempfile())
out$content
#> "/var/folders/fc/n7g_vrvn0sx_st0p8lxb3ts40000gn/T//Rtmp1f2UTM/filec69b5e600215"

Need to change internals of StubbedRequest body parsing to allow this


relates to ropensci/vcr#81

@sckott sckott added this to the v0.4 milestone Jan 15, 2019
sckott added a commit that referenced this issue Feb 9, 2019
StubbedRequest modifications:
allow to_return response body to accept a file connection
add mocking writing egs to stub_request
FIXME: still not quite done as file(<filename>) doesnt work with httr
  if the file already has content in it - see to_file() fxn in stub_request egs
fixes to to_raise in StubbedRequest to handle exception passing

add StubbedRequest tests for to_timeout and to_raise
sckott added a commit that referenced this issue Feb 9, 2019
two different uses: write to a file "manually" and then do mocked request
or use special fxn mock_file() to give file path and content to go in the file
examples added
FIXME: still need to add tests
FIXME: still need to integrate with vcr
sckott added a commit that referenced this issue Jul 25, 2019
@sckott sckott modified the milestones: v0.4, v0.5 Aug 9, 2019
@sckott sckott closed this as completed in #76 Dec 3, 2019
sckott added a commit to ropensci/rnoaa that referenced this issue Mar 23, 2020
* #290 - working on integrating vcr handling writing to disk, not done yet
related: ropensci/vcr#81 ropensci/webmockr#57

* playing with buoy tests, check back in #FIXME

* cpc_prcp test tweaks

* man file updates

* arc2 fixes, use new write to disk setup

* #290 writing to disk work, not done yet

* fixes for lcd and isd tests that also cache files

* fixed some tests #290

* fix storms test

* use relative paths with new vcr version

* move write to disk files to inst/ - test check on travis | ropensci/vcr#164

* try commenting out deleting  user cached files for ersst tests

* comment out one ersst test, does it work now?

* try ersst tests each with different file on disk - was previously using the same file
perhaps that was leading to failure if e.g. file was opened but not closed before next test ran amybe

* remove .Rinstignore, and try inst/test_files in .Rbuildignore if it works on travis

* remove inst/test_files from rbuildignore

* move test files back to tests/files/

* add .Rinstignore for ignoring test on disk files

* woops, needed to fix write_disk_path
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 a pull request may close this issue.

1 participant