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

lhttpc -> hackney. fixes #17 #21

Merged
merged 1 commit into from
Feb 15, 2016
Merged
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ script:
- "[[ ${TRAVIS_OTP_RELEASE} == 18.1 ]] && make elvis || true"
- make .rebar/DEV_MODE
- make
- make test
- make .rebar/DEV_MODE deps eunit
- "[[ ${TRAVIS_OTP_RELEASE} == 18.1 ]] && make dialyzer || true"
12 changes: 8 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
, "1a1c913ac80bb45d3de5fbd74d21e96c45e9e844"
}
}
, { lhttpc
, { hackney
, ".*"
, { git, "git://github.com/esl/lhttpc.git"
, "6530ef818bf904bf4ef615f384d2fc7bae44a6dc"
, { git, "git://github.com/benoitc/hackney.git"
, {tag, "1.4.4"}
}
}
, { neotoma
Expand Down Expand Up @@ -71,6 +71,10 @@
, asn1
, public_key
, ssl
, lhttpc
, ssl_verify_hostname
, idna
, mimerl
, certifi
, hackney
, tdiff
]}.
2 changes: 1 addition & 1 deletion src/katt.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
, asn1
, public_key
, ssl
, lhttpc
, hackney
, tdiff
]}
]}.
2 changes: 1 addition & 1 deletion src/katt_callbacks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ http_request( #katt_request{ method = Method
Hdrs1 = proplists:delete("x-katt-sleep", Hdrs0),
Hdrs = proplists:delete("x-katt-timeout", Hdrs1),
timer:sleep(Sleep),
lhttpc:request(Url, Method, Hdrs, Body, Timeout, []).
katt_util:external_http_request(Url, Method, Hdrs, Body, Timeout, []).

validate_status( #katt_response{status=E}
, #katt_response{status=A}
Expand Down
5 changes: 4 additions & 1 deletion src/katt_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ katt_run(ScenarioFilename, Params0) ->
ok = ensure_started(asn1),
ok = ensure_started(public_key),
ok = ensure_started(ssl),
ok = ensure_started(lhttpc),
ok = ensure_started(idna),
ok = ensure_started(mimerl),
ok = ensure_started(certifi),
ok = ensure_started(hackney),
ok = ensure_started(tdiff),
ok = ensure_started(katt),
katt:run( ScenarioFilename
Expand Down
24 changes: 24 additions & 0 deletions src/katt_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
, is_valid/5
, validate/5
, enumerate/1
, external_http_request/6
]).

%%%_* Includes =================================================================
Expand Down Expand Up @@ -114,6 +115,29 @@ run_result_to_mochijson3({ PassOrFail
, {transaction_results, TransactionResults}
]}.

external_http_request(Url, Method, Hdrs, Body, Timeout, []) ->
BUrl = list_to_binary(Url),
BHdrs = lists:map( fun({Name, Value})->
{list_to_binary(Name), list_to_binary(Value)}
end
, Hdrs
),
Options = [{recv_timeout, Timeout}],
case hackney:request(Method, BUrl, BHdrs, Body, Options) of
{ok, Status, BResHdrs, Client} ->
%% lhttpc was the predecesor of hackney
%% and we're maintaining a backwards compatible return value
{ok, ResBody} = hackney:body(Client),
ResHdrs = lists:map( fun({Name, Value})->
{binary_to_list(Name), binary_to_list(Value)}
end
, BResHdrs
),
{ok, {{Status, ""}, ResHdrs, ResBody}};
Error ->
Error
end.

%%%_* Internal =================================================================

my_float_to_list(X) when is_float(X) ->
Expand Down
10 changes: 5 additions & 5 deletions test/katt_run_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ katt_test_() ->
, file
, fun mock_katt_blueprint_parse_file/1
),
meck:new(lhttpc, [passthrough]),
meck:expect( lhttpc
, request
meck:new(katt_callbacks, [passthrough]),
meck:expect( katt_util
, external_http_request
, fun mock_lhttpc_request/6
)
end
, fun(_) ->
meck:unload(katt_blueprint_parse),
meck:unload(lhttpc)
meck:unload(katt_callbacks)
end
, [ katt_run_basic()
, katt_run_with_params()
Expand Down Expand Up @@ -222,7 +222,7 @@ mock_lhttpc_request( "http://127.0.0.1/step5"
, _Timeout
, _Options
) ->
{ok, {{404, "Not found"}, [{"Content-Type", "text/html"}], <<>>}};
{ok, {{404, []}, [{"Content-Type", "text/html"}], <<>>}};

%% Mock response for test-params:
mock_lhttpc_request( "http://example.com/test-params"
Expand Down
8 changes: 4 additions & 4 deletions test/katt_run_unexpected_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ katt_test_() ->
, file
, fun mock_katt_blueprint_parse_file/1
),
meck:new(lhttpc, [passthrough]),
meck:expect( lhttpc
, request
meck:new(katt_callbacks, [passthrough]),
meck:expect( katt_util
, external_http_request
, fun mock_lhttpc_request/6
)
end
, fun(_) ->
meck:unload(katt_blueprint_parse),
meck:unload(lhttpc)
meck:unload(katt_callbacks)
end
, [ katt_run_with_unexpected_disallow()
, katt_run_with_expected_but_undefined()
Expand Down
8 changes: 4 additions & 4 deletions test/katt_run_validate_type_set_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ katt_test_() ->
, file
, fun mock_katt_blueprint_parse_file/1
),
meck:new(lhttpc, [passthrough]),
meck:expect( lhttpc
, request
meck:new(katt_callbacks, [passthrough]),
meck:expect( katt_util
, external_http_request
, fun mock_lhttpc_request/6
)
end
, fun(_) ->
meck:unload(katt_blueprint_parse),
meck:unload(lhttpc)
meck:unload(katt_callbacks)
end
, [ katt_run_with_set_comparison_strict()
, katt_run_with_set_comparison_strict_fails()
Expand Down