4
4
5
5
6
6
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 ].
28
28
29
29
% %all_tests() ->
30
30
% % case has_unix_socket() of
@@ -38,7 +38,7 @@ http_requests_test_() ->
38
38
fun start /0 ,
39
39
fun stop /1 ,
40
40
fun (ok ) ->
41
- {inparallel , all_tests ()}
41
+ {inorder , all_tests ()}
42
42
end }.
43
43
44
44
start () ->
@@ -50,116 +50,116 @@ stop(ok) -> ok.
50
50
get_request () ->
51
51
URL = <<" http://localhost:8000/get" >>,
52
52
{ok , StatusCode , _ , _ } = hackney :request (get , URL , [], <<>>, []),
53
- ? _assertEqual (200 , StatusCode ).
53
+ ? assertEqual (200 , StatusCode ).
54
54
55
55
request_with_body () ->
56
56
URL = <<" http://localhost:8000/robots.txt" >>,
57
57
ExpectedBody = <<" User-agent: *\n Disallow: /deny\n " >>,
58
58
{ok , 200 , _ , Body } = hackney :request (get , URL , [], <<>>, [{with_body , true }]),
59
- ? _assertEqual (ExpectedBody , Body ).
59
+ ? assertEqual (ExpectedBody , Body ).
60
60
61
61
head_request () ->
62
62
URL = <<" http://localhost:8000/get" >>,
63
63
{ok , StatusCode , _ } = hackney :request (head , URL , [], <<>>, []),
64
- ? _assertEqual (200 , StatusCode ).
64
+ ? assertEqual (200 , StatusCode ).
65
65
66
66
no_content_response () ->
67
67
URL = <<" http://localhost:8000/status/204" >>,
68
68
{ok , StatusCode , _ , _ } = hackney :request (get , URL , [], <<>>, []),
69
- ? _assertEqual (204 , StatusCode ).
69
+ ? assertEqual (204 , StatusCode ).
70
70
71
71
not_modified_response () ->
72
72
URL = <<" http://localhost:8000/status/304" >>,
73
73
{ok , StatusCode , _ , _ } = hackney :request (get , URL , [], <<>>, []),
74
- ? _assertEqual (304 , StatusCode ).
74
+ ? assertEqual (304 , StatusCode ).
75
75
76
76
basic_auth_request () ->
77
77
URL = <<" http://localhost:8000/basic-auth/username/password" >>,
78
78
Options = [{basic_auth , {<<" username" >>, <<" password" >>}}],
79
79
{ok , StatusCode , _ , _ } = hackney :request (get , URL , [], <<>>, Options ),
80
- ? _assertEqual (200 , StatusCode ).
80
+ ? assertEqual (200 , StatusCode ).
81
81
82
82
basic_auth_url_request () ->
83
83
URL = <<" http://username:pass%26word@localhost:8000/basic-auth/username/pass%26word" >>,
84
84
{ok , StatusCode , _ , _ } = hackney :request (get , URL , [], <<>>, []),
85
- ? _assertEqual (200 , StatusCode ).
85
+ ? assertEqual (200 , StatusCode ).
86
86
87
87
basic_auth_request_failed () ->
88
88
URL = <<" http://localhost:8000/basic-auth/username/password" >>,
89
89
Options = [{basic_auth , {<<" wrong" >>, <<" auth" >>}}],
90
90
{ok , StatusCode , _ , _ } = hackney :request (get , URL , [], <<>>, Options ),
91
- ? _assertEqual (401 , StatusCode ).
91
+ ? assertEqual (401 , StatusCode ).
92
92
93
93
set_cookie_request () ->
94
94
URL = <<" http://localhost:8000/cookies/set?k1=v1" >>,
95
95
{ok , _ , Headers , _ } = hackney :request (get , URL , [], <<>>, []),
96
96
Cookies = hackney :cookies (Headers ),
97
97
ExpectedCookies = [{<<" k1" >>, [{<<" k1" >>,<<" v1" >>},{<<" Path" >>,<<" /" >>}]}],
98
- ? _assertEqual (ExpectedCookies , Cookies ).
98
+ ? assertEqual (ExpectedCookies , Cookies ).
99
99
100
100
send_cookies_request () ->
101
101
URL = <<" http://localhost:8000/cookies" >>,
102
102
Options = [{cookie , [{<<" SESSION" >>, <<" 123" >>}]}],
103
103
{ok , _ , _ , Client } = hackney :request (get , URL , [], <<>>, Options ),
104
104
{ok , Body } = hackney :body (Client ),
105
105
Match = re :run (Body , <<" .*\" SESSION\" .*\" 123\" .*" >>),
106
- ? _assertMatch ({match , _ }, Match ).
106
+ ? assertMatch ({match , _ }, Match ).
107
107
108
108
absolute_redirect_request_no_follow () ->
109
109
URL = <<" http://localhost:8000/redirect-to?url=http://localhost:8000/get" >>,
110
110
Options = [{follow_redirect , false }],
111
111
{ok , StatusCode , _ , Client } = hackney :request (get , URL , [], <<>>, Options ),
112
112
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 ).
115
115
116
116
absolute_redirect_request_follow () ->
117
117
URL = <<" http://localhost:8000/redirect-to?url=http://localhost:8000/get" >>,
118
118
Options = [{follow_redirect , true }],
119
119
{ok , StatusCode , _ , Client } = hackney :request (get , URL , [], <<>>, Options ),
120
120
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 ).
123
123
124
124
% relative_redirect_request_no_follow() ->
125
125
% URL = <<"http://localhost:8000/relative-redirect/1">>,
126
126
% Options = [{follow_redirect, false}],
127
127
% {ok, StatusCode, _, Client} = hackney:request(get, URL, [], <<>>, Options),
128
128
% Location = hackney:location(Client),
129
- % [?_assertEqual (302, StatusCode),
130
- % ?_assertEqual (Location, <<"/get">>)].
129
+ % [?assertEqual (302, StatusCode),
130
+ % ?assertEqual (Location, <<"/get">>)].
131
131
132
132
relative_redirect_request_follow () ->
133
133
URL = <<" http://localhost:8000/redirect-to?url=/get" >>,
134
134
Options = [{follow_redirect , true }],
135
135
{ok , StatusCode , _ , Client } = hackney :request (get , URL , [], <<>>, Options ),
136
136
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" >>).
139
139
140
140
async_request () ->
141
141
URL = <<" http://localhost:8000/get" >>,
142
142
Options = [async ],
143
143
{ok , ClientRef } = hackney :get (URL , [], <<>>, Options ),
144
144
{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 ).
147
147
148
148
async_head_request () ->
149
149
URL = <<" http://localhost:8000/get" >>,
150
150
Options = [async ],
151
151
{ok , ClientRef } = hackney :head (URL , [], <<>>, Options ),
152
152
{StatusCode , Keys } = receive_response (ClientRef ),
153
- [ ? _assertEqual (200 , StatusCode ),
154
- ? _assertEqual ([headers , status ], Keys )] .
153
+ ? assertEqual (200 , StatusCode ),
154
+ ? assertEqual ([headers , status ], Keys ).
155
155
156
156
async_no_content_request () ->
157
157
URL = <<" http://localhost:8000/status/204" >>,
158
158
Options = [async ],
159
159
{ok , ClientRef } = hackney :get (URL , [], <<>>, Options ),
160
160
{StatusCode , Keys } = receive_response (ClientRef ),
161
- [ ? _assertEqual (204 , StatusCode ),
162
- ? _assertEqual ([headers , status ], Keys )] .
161
+ ? assertEqual (204 , StatusCode ),
162
+ ? assertEqual ([headers , status ], Keys ).
163
163
164
164
test_duplicate_headers () ->
165
165
URL = <<" http://localhost:8000/post" >>,
@@ -169,7 +169,7 @@ test_duplicate_headers() ->
169
169
{ok , 200 , _H , JsonBody } = hackney :post (URL , Headers , Body , Options ),
170
170
Obj = jsone :decode (JsonBody , [{object_format , proplist }]),
171
171
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 )).
173
173
174
174
test_custom_host_headers () ->
175
175
URL = <<" http://localhost:8000/get" >>,
@@ -178,32 +178,34 @@ test_custom_host_headers() ->
178
178
{ok , 200 , _H , JsonBody } = hackney :get (URL , Headers , <<>>, Options ),
179
179
Obj = jsone :decode (JsonBody , [{object_format , proplist }]),
180
180
ReqHeaders = proplists :get_value (<<" headers" >>, Obj ),
181
- ? _assertEqual (<<" myhost.com" >>, proplists :get_value (<<" Host" >>, ReqHeaders )).
181
+ ? assertEqual (<<" myhost.com" >>, proplists :get_value (<<" Host" >>, ReqHeaders )).
182
182
183
183
test_frees_manager_ets_when_body_is_in_client () ->
184
184
URL = <<" http://localhost:8000/get" >>,
185
185
BeforeCount = ets :info (hackney_manager_refs , size ),
186
186
{ok , 200 , _ , Client } = hackney :get (URL ),
187
187
DuringCount = ets :info (hackney_manager_refs , size ),
188
188
{ok , _unusedBody } = hackney :body (Client ),
189
+ timer :sleep (10 ),
189
190
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 ).
192
193
193
194
test_frees_manager_ets_when_body_is_in_response () ->
194
195
URL = <<" http://localhost:8000/get" >>,
195
196
Headers = [],
196
197
Options = [with_body ],
197
198
BeforeCount = ets :info (hackney_manager_refs , size ),
198
199
{ok , 200 , _ , _ } = hackney :get (URL , Headers , <<>>, Options ),
200
+ timer :sleep (10 ),
199
201
AfterCount = ets :info (hackney_manager_refs , size ),
200
- ? _assertEqual (BeforeCount , AfterCount ).
202
+ ? assertEqual (BeforeCount , AfterCount ).
201
203
202
204
203
205
% %local_socket_request() ->
204
206
% % URL = <<"http+unix://httpbin.sock/get">>,
205
207
% % {ok, StatusCode, _, _} = hackney:request(get, URL, [], <<>>, []),
206
- % % ?_assertEqual (200, StatusCode).
208
+ % % ?assertEqual (200, StatusCode).
207
209
208
210
209
211
% % Helpers
0 commit comments