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

ignore tzdata #151

Open
bryanhuntesl opened this issue Feb 13, 2020 · 2 comments
Open

ignore tzdata #151

bryanhuntesl opened this issue Feb 13, 2020 · 2 comments

Comments

@bryanhuntesl
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

bryanhuntesl commented Feb 14, 2020

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 ?

exvcr/lib/exvcr/handler.ex

Lines 172 to 183 in b45c6af

defp ignore_request?(request, recorder) do
ignore_localhost = ExVCR.Recorder.options(recorder)[:ignore_localhost] || ExVCR.Setting.get(:ignore_localhost)
if ignore_localhost do
adapter = ExVCR.Recorder.options(recorder)[:adapter]
params = adapter.generate_keys_for_request(request)
url = to_string(params[:url])
Regex.match?(~r[https?://localhost], url)
else
false
end
end

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

No branches or pull requests

1 participant