Skip to content

Commit cfd50b6

Browse files
committed
simplifies integration tests suite
1 parent e9fa5cd commit cfd50b6

File tree

1 file changed

+54
-52
lines changed

1 file changed

+54
-52
lines changed

test/hackney_integration_tests.erl

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44

55

66
all_tests() ->
7-
[get_request(),
8-
request_with_body(),
9-
head_request(),
10-
no_content_response(),
11-
not_modified_response(),
12-
basic_auth_request_failed(),
13-
basic_auth_request(),
14-
basic_auth_url_request(),
15-
set_cookie_request(),
16-
send_cookies_request(),
17-
absolute_redirect_request_no_follow(),
18-
absolute_redirect_request_follow(),
19-
% relative_redirect_request_no_follow(),
20-
relative_redirect_request_follow(),
21-
test_duplicate_headers(),
22-
test_custom_host_headers(),
23-
async_request(),
24-
async_head_request(),
25-
async_no_content_request(),
26-
test_frees_manager_ets_when_body_is_in_client(),
27-
test_frees_manager_ets_when_body_is_in_response()].
7+
[fun get_request/0,
8+
fun request_with_body/0,
9+
fun head_request/0,
10+
fun no_content_response/0,
11+
fun not_modified_response/0,
12+
fun basic_auth_request_failed/0,
13+
fun basic_auth_request/0,
14+
fun basic_auth_url_request/0,
15+
fun set_cookie_request/0,
16+
fun send_cookies_request/0,
17+
fun absolute_redirect_request_no_follow/0,
18+
fun absolute_redirect_request_follow/0,
19+
% fun relative_redirect_request_no_follow/0,
20+
fun relative_redirect_request_follow/0,
21+
fun test_duplicate_headers/0,
22+
fun test_custom_host_headers/0,
23+
fun async_request/0,
24+
fun async_head_request/0,
25+
fun async_no_content_request/0,
26+
fun test_frees_manager_ets_when_body_is_in_client/0,
27+
fun test_frees_manager_ets_when_body_is_in_response/0].
2828

2929
%%all_tests() ->
3030
%% case has_unix_socket() of
@@ -38,7 +38,7 @@ http_requests_test_() ->
3838
fun start/0,
3939
fun stop/1,
4040
fun(ok) ->
41-
{inparallel, all_tests()}
41+
{inorder, all_tests()}
4242
end}.
4343

4444
start() ->
@@ -50,116 +50,116 @@ stop(ok) -> ok.
5050
get_request() ->
5151
URL = <<"http://localhost:8000/get">>,
5252
{ok, StatusCode, _, _} = hackney:request(get, URL, [], <<>>, []),
53-
?_assertEqual(200, StatusCode).
53+
?assertEqual(200, StatusCode).
5454

5555
request_with_body() ->
5656
URL = <<"http://localhost:8000/robots.txt">>,
5757
ExpectedBody = <<"User-agent: *\nDisallow: /deny\n">>,
5858
{ok, 200, _, Body} = hackney:request(get, URL, [], <<>>, [{with_body, true}]),
59-
?_assertEqual(ExpectedBody, Body).
59+
?assertEqual(ExpectedBody, Body).
6060

6161
head_request() ->
6262
URL = <<"http://localhost:8000/get">>,
6363
{ok, StatusCode, _} = hackney:request(head, URL, [], <<>>, []),
64-
?_assertEqual(200, StatusCode).
64+
?assertEqual(200, StatusCode).
6565

6666
no_content_response() ->
6767
URL = <<"http://localhost:8000/status/204">>,
6868
{ok, StatusCode, _, _} = hackney:request(get, URL, [], <<>>, []),
69-
?_assertEqual(204, StatusCode).
69+
?assertEqual(204, StatusCode).
7070

7171
not_modified_response() ->
7272
URL = <<"http://localhost:8000/status/304">>,
7373
{ok, StatusCode, _, _} = hackney:request(get, URL, [], <<>>, []),
74-
?_assertEqual(304, StatusCode).
74+
?assertEqual(304, StatusCode).
7575

7676
basic_auth_request() ->
7777
URL = <<"http://localhost:8000/basic-auth/username/password">>,
7878
Options = [{basic_auth, {<<"username">>, <<"password">>}}],
7979
{ok, StatusCode, _, _} = hackney:request(get, URL, [], <<>>, Options),
80-
?_assertEqual(200, StatusCode).
80+
?assertEqual(200, StatusCode).
8181

8282
basic_auth_url_request() ->
8383
URL = <<"http://username:pass%26word@localhost:8000/basic-auth/username/pass%26word">>,
8484
{ok, StatusCode, _, _} = hackney:request(get, URL, [], <<>>, []),
85-
?_assertEqual(200, StatusCode).
85+
?assertEqual(200, StatusCode).
8686

8787
basic_auth_request_failed() ->
8888
URL = <<"http://localhost:8000/basic-auth/username/password">>,
8989
Options = [{basic_auth, {<<"wrong">>, <<"auth">>}}],
9090
{ok, StatusCode, _, _} = hackney:request(get, URL, [], <<>>, Options),
91-
?_assertEqual(401, StatusCode).
91+
?assertEqual(401, StatusCode).
9292

9393
set_cookie_request() ->
9494
URL = <<"http://localhost:8000/cookies/set?k1=v1">>,
9595
{ok, _, Headers, _} = hackney:request(get, URL, [], <<>>, []),
9696
Cookies = hackney:cookies(Headers),
9797
ExpectedCookies = [{<<"k1">>, [{<<"k1">>,<<"v1">>},{<<"Path">>,<<"/">>}]}],
98-
?_assertEqual(ExpectedCookies, Cookies).
98+
?assertEqual(ExpectedCookies, Cookies).
9999

100100
send_cookies_request() ->
101101
URL = <<"http://localhost:8000/cookies">>,
102102
Options = [{cookie, [{<<"SESSION">>, <<"123">>}]}],
103103
{ok, _, _, Client} = hackney:request(get, URL, [], <<>>, Options),
104104
{ok, Body} = hackney:body(Client),
105105
Match = re:run(Body, <<".*\"SESSION\".*\"123\".*">>),
106-
?_assertMatch({match, _}, Match).
106+
?assertMatch({match, _}, Match).
107107

108108
absolute_redirect_request_no_follow() ->
109109
URL = <<"http://localhost:8000/redirect-to?url=http://localhost:8000/get">>,
110110
Options = [{follow_redirect, false}],
111111
{ok, StatusCode, _, Client} = hackney:request(get, URL, [], <<>>, Options),
112112
Location = hackney:location(Client),
113-
[?_assertEqual(302, StatusCode),
114-
?_assertEqual(<<"http://localhost:8000/get">>, Location)].
113+
?assertEqual(302, StatusCode),
114+
?assertEqual(<<"http://localhost:8000/get">>, Location).
115115

116116
absolute_redirect_request_follow() ->
117117
URL = <<"http://localhost:8000/redirect-to?url=http://localhost:8000/get">>,
118118
Options = [{follow_redirect, true}],
119119
{ok, StatusCode, _, Client} = hackney:request(get, URL, [], <<>>, Options),
120120
Location = hackney:location(Client),
121-
[?_assertEqual(200, StatusCode),
122-
?_assertEqual(<<"http://localhost:8000/get">>, Location)].
121+
?assertEqual(200, StatusCode),
122+
?assertEqual(<<"http://localhost:8000/get">>, Location).
123123

124124
%relative_redirect_request_no_follow() ->
125125
% URL = <<"http://localhost:8000/relative-redirect/1">>,
126126
% Options = [{follow_redirect, false}],
127127
% {ok, StatusCode, _, Client} = hackney:request(get, URL, [], <<>>, Options),
128128
% Location = hackney:location(Client),
129-
% [?_assertEqual(302, StatusCode),
130-
% ?_assertEqual(Location, <<"/get">>)].
129+
% [?assertEqual(302, StatusCode),
130+
% ?assertEqual(Location, <<"/get">>)].
131131

132132
relative_redirect_request_follow() ->
133133
URL = <<"http://localhost:8000/redirect-to?url=/get">>,
134134
Options = [{follow_redirect, true}],
135135
{ok, StatusCode, _, Client} = hackney:request(get, URL, [], <<>>, Options),
136136
Location = hackney:location(Client),
137-
[?_assertEqual(200, StatusCode),
138-
?_assertEqual(Location, <<"http://localhost:8000/get">>)].
137+
?assertEqual(200, StatusCode),
138+
?assertEqual(Location, <<"http://localhost:8000/get">>).
139139

140140
async_request() ->
141141
URL = <<"http://localhost:8000/get">>,
142142
Options = [async],
143143
{ok, ClientRef} = hackney:get(URL, [], <<>>, Options),
144144
{StatusCode, Keys} = receive_response(ClientRef),
145-
[?_assertEqual(200, StatusCode),
146-
?_assertEqual([body, headers, status], Keys)].
145+
?assertEqual(200, StatusCode),
146+
?assertEqual([body, headers, status], Keys).
147147

148148
async_head_request() ->
149149
URL = <<"http://localhost:8000/get">>,
150150
Options = [async],
151151
{ok, ClientRef} = hackney:head(URL, [], <<>>, Options),
152152
{StatusCode, Keys} = receive_response(ClientRef),
153-
[?_assertEqual(200, StatusCode),
154-
?_assertEqual([headers, status], Keys)].
153+
?assertEqual(200, StatusCode),
154+
?assertEqual([headers, status], Keys).
155155

156156
async_no_content_request() ->
157157
URL = <<"http://localhost:8000/status/204">>,
158158
Options = [async],
159159
{ok, ClientRef} = hackney:get(URL, [], <<>>, Options),
160160
{StatusCode, Keys} = receive_response(ClientRef),
161-
[?_assertEqual(204, StatusCode),
162-
?_assertEqual([headers, status], Keys)].
161+
?assertEqual(204, StatusCode),
162+
?assertEqual([headers, status], Keys).
163163

164164
test_duplicate_headers() ->
165165
URL = <<"http://localhost:8000/post">>,
@@ -169,7 +169,7 @@ test_duplicate_headers() ->
169169
{ok, 200, _H, JsonBody} = hackney:post(URL, Headers, Body, Options),
170170
Obj = jsone:decode(JsonBody, [{object_format, proplist}]),
171171
ReqHeaders = proplists:get_value(<<"headers">>, Obj),
172-
?_assertEqual(<<"application/json">>, proplists:get_value(<<"Content-Type">>, ReqHeaders)).
172+
?assertEqual(<<"application/json">>, proplists:get_value(<<"Content-Type">>, ReqHeaders)).
173173

174174
test_custom_host_headers() ->
175175
URL = <<"http://localhost:8000/get">>,
@@ -178,32 +178,34 @@ test_custom_host_headers() ->
178178
{ok, 200, _H, JsonBody} = hackney:get(URL, Headers, <<>>, Options),
179179
Obj = jsone:decode(JsonBody, [{object_format, proplist}]),
180180
ReqHeaders = proplists:get_value(<<"headers">>, Obj),
181-
?_assertEqual(<<"myhost.com">>, proplists:get_value(<<"Host">>, ReqHeaders)).
181+
?assertEqual(<<"myhost.com">>, proplists:get_value(<<"Host">>, ReqHeaders)).
182182

183183
test_frees_manager_ets_when_body_is_in_client() ->
184184
URL = <<"http://localhost:8000/get">>,
185185
BeforeCount = ets:info(hackney_manager_refs, size),
186186
{ok, 200, _, Client} = hackney:get(URL),
187187
DuringCount = ets:info(hackney_manager_refs, size),
188188
{ok, _unusedBody} = hackney:body(Client),
189+
timer:sleep(10),
189190
AfterCount = ets:info(hackney_manager_refs, size),
190-
?_assertEqual(DuringCount, BeforeCount + 1),
191-
?_assertEqual(BeforeCount, AfterCount).
191+
?assertEqual(DuringCount, BeforeCount + 1),
192+
?assertEqual(BeforeCount, AfterCount).
192193

193194
test_frees_manager_ets_when_body_is_in_response() ->
194195
URL = <<"http://localhost:8000/get">>,
195196
Headers = [],
196197
Options = [with_body],
197198
BeforeCount = ets:info(hackney_manager_refs, size),
198199
{ok, 200, _, _} = hackney:get(URL, Headers, <<>>, Options),
200+
timer:sleep(10),
199201
AfterCount = ets:info(hackney_manager_refs, size),
200-
?_assertEqual(BeforeCount, AfterCount).
202+
?assertEqual(BeforeCount, AfterCount).
201203

202204

203205
%%local_socket_request() ->
204206
%% URL = <<"http+unix://httpbin.sock/get">>,
205207
%% {ok, StatusCode, _, _} = hackney:request(get, URL, [], <<>>, []),
206-
%% ?_assertEqual(200, StatusCode).
208+
%% ?assertEqual(200, StatusCode).
207209

208210

209211
%% Helpers

0 commit comments

Comments
 (0)