ropensci / vcr

Record HTTP calls and replay them
https://docs.ropensci.org/vcr
Other
77 stars 12 forks source link

Workflow advice #117

Closed maelle closed 3 years ago

maelle commented 4 years ago

So say I have now wrapped all the tests of my package in cassettes.

The tests assess how my package handles responses of the web API at version blabla.

How do I make sure I'm keeping up with web API changes, or even web API failures? Should I have e.g. one build that doesn't use the cassettes on Travis? Do you have any example?

sckott commented 4 years ago

There's a lot of variables here as you know, so it's hard to give one solution.

In the recent version we added https://github.com/ropensci/vcr/blob/master/NEWS.md#new-features re_record_interval setting, so e.g., you could tell vcr to re-record real interactions every 5 days, or 24 hrs, or whatever. This approach is a sort of hack I guess, so that test runs are fast by using cached request/responses, but then more up to date with the current web API than if they weren't updated

Another approach is as you suggested: have some tests that make real HTTP requests. Of course I'd skip on cran these real requests in case they fail at some point. I haven't seen any best practices for this approach. I do this approach sort of by accident in some packages since vcr doesn't yet (but it's almost ready) support when http requests write to disk, e.g., in rnoaa

If you do the re-record interval setting thing, that I guess would take care of any changes in the web API since when re-recording real requests, it should hit upon any problems, right?

maelle commented 4 years ago

Ideal build matrix IMO

maelle commented 4 years ago

(plus with the re-record you mention)

sckott commented 4 years ago

commits within the repo

does that just mean no PR's?

maelle commented 4 years ago

No PRs from external repos

sckott commented 4 years ago

so PRs from another branch within the repo + commits to default branch?

maelle commented 4 years ago

Yes

sckott commented 4 years ago

what does "A few builds with vcr turned on" entail? How are those builds different? can you list all the builds out?

maelle commented 4 years ago

Ah sorry, one would be enough but often people already have several builds (e.g. a matrix with different OS and R versions)

sckott commented 4 years ago

Should we add some text to the book for this?

maelle commented 4 years ago

Yes but ideally it'd go with an example package repo. I was thinking that example repo could have two GitHub actions workflows, 1 for any push with vcr turned on, and 1 that runs regularly with vcr turned off.

how could one create that example package?

sckott commented 4 years ago

You could use the crandb api or the cranchecks api or similar

maelle commented 4 years ago

I've just added VCR_TURN_OFF to https://github.com/ropensci/ropenaq/blob/master/.github/workflows/R-CMD-check.yaml (but some builds are failing because of dependencies). All jobs are run once a day, I think I might switch to once a week.

sckott commented 4 years ago

thanks for trying that, hopefully it works well