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

remove_exactor #224

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
plugins: [Styler]
]
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
elixir main-otp-27
75 changes: 1 addition & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,80 +59,7 @@ end

### Usage

Add `use ExVCR.Mock` to the test module. This mocks `ibrowse` by default. For
using `hackney`, specify `adapter: ExVCR.Adapter.Hackney` options as follows.

##### Example with ibrowse

```elixir
defmodule ExVCR.Adapter.IBrowseTest do
use ExUnit.Case, async: true
use ExVCR.Mock

setup do
ExVCR.Config.cassette_library_dir("fixture/vcr_cassettes")
:ok
end

test "example single request" do
use_cassette "example_ibrowse" do
:ibrowse.start
{:ok, status_code, _headers, body} = :ibrowse.send_req('http://example.com', [], :get)
assert status_code == '200'
assert to_string(body) =~ ~r/Example Domain/
end
end

test "httpotion" do
use_cassette "example_httpotion" do
HTTPotion.start
assert HTTPotion.get("http://example.com", []).body =~ ~r/Example Domain/
end
end
end
```

##### Example with hackney

```elixir
defmodule ExVCR.Adapter.HackneyTest do
use ExUnit.Case, async: true
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney

setup_all do
HTTPoison.start
:ok
end

test "get request" do
use_cassette "httpoison_get" do
assert HTTPoison.get!("http://example.com").body =~ ~r/Example Domain/
end
end
end
```

##### Example with httpc

```elixir
defmodule ExVCR.Adapter.HttpcTest do
use ExUnit.Case, async: true
use ExVCR.Mock, adapter: ExVCR.Adapter.Httpc

setup_all do
:inets.start
:ok
end

test "get request" do
use_cassette "example_httpc_request" do
{:ok, result} = :httpc.request('http://example.com')
{{_http_version, _status_code = 200, _reason_phrase}, _headers, body} = result
assert to_string(body) =~ ~r/Example Domain/
end
end
end
```
Add `use ExVCR.Mock` to the test module. This mocks `finch` by default.

##### Example with Finch

Expand Down
5 changes: 2 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Config

config :exvcr, [
config :exvcr,
global_mock: false,
vcr_cassette_library_dir: "fixture/vcr_cassettes",
custom_cassette_library_dir: "fixture/custom_cassettes",
Expand All @@ -13,6 +13,5 @@ config :exvcr, [
ignore_localhost: false,
enable_global_settings: false,
strict_mode: false
]

if Mix.env() == :test, do: import_config "test.exs"
if Mix.env() == :test, do: import_config("test.exs")
3 changes: 1 addition & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Config

config :exvcr, [
config :exvcr,
global_mock: System.get_env("GLOBAL_MOCK") == "true"
]
20 changes: 0 additions & 20 deletions fixture/custom_cassettes/httpoison_get_alternate.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
"headers": [],
"method": "get",
"options": [],
"url": "http://invalid_url"
"request_body": "",
"url": "http://example.com/"
},
"response": {
"body": [
"conn_failed",
[
"error",
"nxdomain"
]
],
"binary": false,
"body": "%{reason: \"some made up error which could happen, in theory\"}",
"headers": [],
"status_code": null,
"type": "error"
}
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"headers": [],
"method": "get",
"options": [],
"url": "http://example.com"
"request_body": "",
"url": "http://example.com/"
},
"response": {
"body": [
"req_timedout"
],
"binary": false,
"body": "%{reason: :timeout}",
"headers": [],
"status_code": null,
"type": "error"
}
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"headers": [],
"method": "get",
"options": [],
"url": "http://invalid_url"
"request_body": "",
"url": "http://example.com/"
},
"response": {
"body": "nxdomain",
"binary": false,
"body": "%Mint.HTTPError{module: Mint.HTTP2, reason: :too_many_concurrent_requests}",
"headers": [],
"status_code": null,
"type": "error"
}
}
]
]
19 changes: 19 additions & 0 deletions fixture/custom_cassettes/req_tuple_transport_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"request": {
"body": "",
"headers": [],
"method": "get",
"options": [],
"request_body": "",
"url": "http://example.com/"
},
"response": {
"binary": false,
"body": "%Req.TransportError{reason: {:bad_alpn_protocol, \"h3\"}}",
"headers": [],
"status_code": null,
"type": "error"
}
}
]
116 changes: 86 additions & 30 deletions fixture/vcr_cassettes/different_headers_on.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,104 @@
[
{
"request": {
"body": "body",
"headers": {
"User-Agent": "My App"
},
"method": "post",
"options": [],
"body": "body",
"url": "http://localhost:34006/server",
"headers": [
[
"accept-encoding",
"gzip"
],
[
"user-agent",
"My App"
]
],
"request_body": "",
"url": "http://localhost:34006/server"
"method": "post"
},
"response": {
"body": "test_response_before",
"headers": {
"connection": "keep-alive",
"server": "Cowboy",
"date": "Thu, 21 Apr 2016 17:40:10 GMT",
"content-length": "20"
},
"status_code": 200,
"type": "ok"
"binary": true,
"type": "ok",
"body": "g20AAAAoH4sIAAAAAAAAAytJLS6JL0otLsjPK06NT0pNyy9KBQDESo7NFAAAAA==",
"headers": [
[
"date",
"Wed, 11 Dec 2024 18:48:00 GMT"
],
[
"content-length",
"40"
],
[
"content-encoding",
"gzip"
],
[
"vary",
"accept-encoding"
],
[
"cache-control",
"max-age=0, private, must-revalidate"
],
[
"content-type",
"text/plain"
]
],
"status_code": 200
}
},
{
"request": {
"body": "body",
"headers": {
"User-Agent": "Other App"
},
"method": "post",
"options": [],
"body": "body",
"url": "http://localhost:34006/server",
"headers": [
[
"accept-encoding",
"gzip"
],
[
"user-agent",
"Other App"
]
],
"request_body": "",
"url": "http://localhost:34006/server"
"method": "post"
},
"response": {
"body": "test_response_after",
"headers": {
"connection": "keep-alive",
"server": "Cowboy",
"date": "Thu, 21 Apr 2016 17:40:10 GMT",
"content-length": "19"
},
"status_code": 200,
"type": "ok"
"binary": true,
"type": "ok",
"body": "g20AAAAnH4sIAAAAAAAAAytJLS6JL0otLsjPK06NT0wrSS0CABxtfuYTAAAA",
"headers": [
[
"date",
"Wed, 11 Dec 2024 18:48:00 GMT"
],
[
"content-length",
"39"
],
[
"content-encoding",
"gzip"
],
[
"vary",
"accept-encoding"
],
[
"cache-control",
"max-age=0, private, must-revalidate"
],
[
"content-type",
"text/plain"
]
],
"status_code": 200
}
}
]
23 changes: 0 additions & 23 deletions fixture/vcr_cassettes/error_ibrowse.json

This file was deleted.

1 change: 1 addition & 0 deletions fixture/vcr_cassettes/error_req.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading