parroty / exvcr

HTTP request/response recording library for elixir, inspired by VCR.
MIT License
720 stars 131 forks source link

ignore tzdata #151

Open bryanhuntesl opened 4 years ago

bryanhuntesl commented 4 years ago

This project is using tzdata which downloads the latest timezone information on startup - obviously we don't want to mock this out, any idea how I can get exvcr to ignore requests to "data.iana.org" ?

Randomized with seed 691355
17:25:27.010 [error] GenServer :tzdata_release_updater terminating
** (ExVCR.RequestNotMatchError) Request did not match with any one in the current cassette: test/fixtures/vcr_cassettes/example_create_device_success.json.
Delete the current cassette with [mix vcr.delete] and re-record.

Request: [:head, "https://data.iana.org/time-zones/tzdata-latest.tar.gz", [], "", []]

    (exvcr) lib/exvcr/handler.ex:194: ExVCR.Handler.raise_error_if_cassette_already_exists/2
    (exvcr) lib/exvcr/handler.ex:165: ExVCR.Handler.get_response_from_server/3
    (tzdata) lib/tzdata/http_client/hackney.ex:17: Tzdata.HTTPClient.Hackney.head/3
    (tzdata) lib/tzdata/data_loader.ex:46: Tzdata.DataLoader.last_modified_of_latest_available/1
    (tzdata) lib/tzdata/release_updater.ex:81: Tzdata.ReleaseUpdater.loaded_tzdata_matches_remote_last_modified?/0
    (tzdata) lib/tzdata/release_updater.ex:42: Tzdata.ReleaseUpdater.poll_for_update/0
    (tzdata) lib/tzdata/release_updater.ex:19: Tzdata.ReleaseUpdater.handle_info/2
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
    (hackney) :hackney.request(:head, "https://data.iana.org/time-zones/tzdata-latest.tar.gz", [], "", [])
    (hackney) :hackney.head("https://data.iana.org/time-zones/tzdata-latest.tar.gz", [], "", [])
Last message: :check_if_time_to_update
bryanhuntesl commented 4 years ago

In case anyone else reads this ticket, I found a workaround for the specific case of tzdata - in my config/test.exs I added the following line to prevent tzdata downloading it's updates.

config :tzdata, :autoupdate, :disabled

It would still be interesting/useful if exvcr had a means to prevent mocking of requests by hostname, I know a functionality exists for localhost but perhaps it would be nice if it were more general.

Thanks

bryanhuntesl commented 4 years ago

I guess this is the place where such a thing would be implemented, let me know if such a feature is of interest to you ?

https://github.com/parroty/exvcr/blob/b45c6af4231b087c83977485c1e0e3ae40bcacce/lib/exvcr/handler.ex#L172-L183