Skip to content

Commit

Permalink
Added test for aws_request
Browse files Browse the repository at this point in the history
  • Loading branch information
couchemar committed Oct 9, 2012
1 parent e3fd18a commit d44cdee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{erl_opts, [debug_info]}.

{deps, [{meck, ".*", {git, "https://github.com/eproxus/meck.git", "master"}}]}.
26 changes: 26 additions & 0 deletions test/erlcloud_aws_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-module(erlcloud_aws_tests).
-include_lib("eunit/include/eunit.hrl").

request_test() ->
meck:new(httpc, [unstick]),
meck:expect(httpc, request, fun(_) -> {ok, {{0, 200, 0}, 0, ok}} end),
ok = erlcloud_aws:aws_request(get, "host", "/", [], "id", "key"),
[{_, {httpc, request, [Url]}, _}] = meck:history(httpc),
test_url(https, "host", 443, "/", Url),
meck:unload(httpc).


request2_test() ->
meck:new(httpc, [unstick]),
meck:expect(httpc, request, fun(_) -> {ok, {{0, 200, 0}, 0, ok}} end),
ok = erlcloud_aws:aws_request(get, "http", "host1", "9999", "/path1", [], "id", "key"),
[{_, {httpc, request, [Url]}, _}] = meck:history(httpc),
test_url(http, "host1", 9999, "/path1", Url),
meck:unload(httpc).

test_url(ExpScheme, ExpHost, ExpPort, ExpPath, Url) ->
{Scheme, _UserInfo, Host, Port, Path, _Query} = http_uri:parse(Url),
?assertEqual(ExpScheme, Scheme),
?assertEqual(ExpHost, Host),
?assertEqual(ExpPort, Port),
?assertEqual(ExpPath, Path).

0 comments on commit d44cdee

Please sign in to comment.