From d44cdee74fb5ed992ecb95915da8f6b5597c6689 Mon Sep 17 00:00:00 2001 From: Andrey Pavlov Date: Tue, 9 Oct 2012 17:48:59 +0400 Subject: [PATCH] Added test for aws_request --- rebar.config | 2 ++ test/erlcloud_aws_tests.erl | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 test/erlcloud_aws_tests.erl diff --git a/rebar.config b/rebar.config index 0f5d40e6..6bd77283 100644 --- a/rebar.config +++ b/rebar.config @@ -1 +1,3 @@ {erl_opts, [debug_info]}. + +{deps, [{meck, ".*", {git, "https://github.com/eproxus/meck.git", "master"}}]}. diff --git a/test/erlcloud_aws_tests.erl b/test/erlcloud_aws_tests.erl new file mode 100644 index 00000000..ed00bc9d --- /dev/null +++ b/test/erlcloud_aws_tests.erl @@ -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).