Skip to content

Commit

Permalink
Add tests to cover passthrough scenario after a cassette has been used
Browse files Browse the repository at this point in the history
  • Loading branch information
surik committed Sep 29, 2020
1 parent 7ccdbb1 commit 38b4bff
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1 deletion.
25 changes: 25 additions & 0 deletions fixture/vcr_cassettes/hackney_get_localhost.json
@@ -0,0 +1,25 @@
[
{
"request": {
"body": "",
"headers": [],
"method": "get",
"options": {
"with_body": "true"
},
"request_body": "",
"url": "http://localhost:34009/server"
},
"response": {
"binary": false,
"body": "test_response",
"headers": {
"server": "Cowboy",
"date": "Tue, 29 Sep 2020 11:50:14 GMT",
"content-length": "13"
},
"status_code": 200,
"type": "ok"
}
}
]
30 changes: 30 additions & 0 deletions fixture/vcr_cassettes/httpc_get_localhost.json
@@ -0,0 +1,30 @@
[
{
"request": {
"body": "",
"headers": [],
"method": "get",
"options": {
"httpc_options": [],
"http_options": []
},
"request_body": "",
"url": "http://localhost:34010/server"
},
"response": {
"binary": false,
"body": "test_response",
"headers": {
"date": "Tue, 29 Sep 2020 11:52:26 GMT",
"server": "Cowboy",
"content-length": "13"
},
"status_code": [
"HTTP/1.1",
200,
"OK"
],
"type": "ok"
}
}
]
23 changes: 23 additions & 0 deletions fixture/vcr_cassettes/ibrowse_get_localhost.json
@@ -0,0 +1,23 @@
[
{
"request": {
"body": "",
"headers": [],
"method": "get",
"options": [],
"request_body": "",
"url": "http://localhost:34011/server"
},
"response": {
"binary": false,
"body": "test_response",
"headers": {
"server": "Cowboy",
"date": "Tue, 29 Sep 2020 11:56:58 GMT",
"content-length": "13"
},
"status_code": 200,
"type": "ok"
}
}
]
16 changes: 16 additions & 0 deletions test/adapter_hackney_test.exs
Expand Up @@ -2,11 +2,27 @@ defmodule ExVCR.Adapter.HackneyTest do
use ExUnit.Case, async: true
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney

@port 34009

setup_all do
HttpServer.start(path: "/server", port: @port, response: "test_response")
{:ok, _} = HTTPoison.start
on_exit fn ->
HttpServer.stop(@port)
end
:ok
end

test "passthrough works after cassette has been used" do
url = "http://localhost:#{@port}/server"
use_cassette "hackney_get_localhost" do
{:ok, status_code, _headers, _body} = :hackney.request(:get, url, [], [], [with_body: true])
assert status_code == 200
end
{:ok, status_code, _headers, _body} = :hackney.request(:get, url, [], [], [with_body: true])
assert status_code == 200
end

test "hackney request" do
use_cassette "hackney_get" do
{:ok, status_code, headers, client} = :hackney.request(:get, "http://www.example.com", [], [], [])
Expand Down
18 changes: 18 additions & 0 deletions test/adapter_httpc_test.exs
Expand Up @@ -2,11 +2,29 @@ defmodule ExVCR.Adapter.HttpcTest do
use ExUnit.Case, async: true
use ExVCR.Mock, adapter: ExVCR.Adapter.Httpc

@port 34010

setup_all do
HttpServer.start(path: "/server", port: @port, response: "test_response")
Application.ensure_started(:inets)
on_exit fn ->
HttpServer.stop(@port)
end
:ok
end

test "passthrough works after cassette has been used" do
url = "http://localhost:#{@port}/server" |> to_char_list()
use_cassette "httpc_get_localhost" do
{:ok, result} = :httpc.request(url)
{{_http_version, status_code, _reason_phrase}, _headers, _body} = result
assert status_code == 200
end
{:ok, result} = :httpc.request(url)
{{_http_version, status_code, _reason_phrase}, _headers, _body} = result
assert status_code == 200
end

test "example httpc request/1" do
use_cassette "example_httpc_request_1" do
{:ok, result} = :httpc.request('http://example.com')
Expand Down
19 changes: 18 additions & 1 deletion test/adapter_ibrowse_test.exs
Expand Up @@ -2,12 +2,29 @@ defmodule ExVCR.Adapter.IBrowseTest do
use ExUnit.Case, async: true
use ExVCR.Mock

@port 34011

setup_all do
HTTPotion.start
HttpServer.start(path: "/server", port: @port, response: "test_response")
Application.ensure_started(:ibrowse)
on_exit fn ->
HttpServer.stop(@port)
end
:ok
end


test "passthrough works after cassette has been used" do
url = "http://localhost:#{@port}/server" |> to_char_list()
use_cassette "ibrowse_get_localhost" do
{:ok, status_code, _headers, _body} = :ibrowse.send_req(url, [], :get)
assert status_code == '200'
end
{:ok, status_code, _headers, _body} = :ibrowse.send_req(url, [], :get)
assert status_code == '200'
end


test "example single request" do
use_cassette "example_ibrowse" do
{:ok, status_code, headers, body} = :ibrowse.send_req('http://example.com', [], :get)
Expand Down

0 comments on commit 38b4bff

Please sign in to comment.