Skip to content

Commit e80cca7

Browse files
committed
Update tests to use new connect syntax
1 parent 52a87d4 commit e80cca7

File tree

9 files changed

+239
-53
lines changed

9 files changed

+239
-53
lines changed

t/01-basic.t

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ __DATA__
3333
content_by_lua '
3434
local http = require "resty.http"
3535
local httpc = http.new()
36-
httpc:connect("127.0.0.1", ngx.var.server_port)
36+
httpc:connect{
37+
scheme = "http",
38+
host = "127.0.0.1",
39+
port = ngx.var.server_port
40+
}
3741
3842
local res, err = httpc:request{
3943
path = "/b"
@@ -64,7 +68,11 @@ OK
6468
content_by_lua '
6569
local http = require "resty.http"
6670
local httpc = http.new()
67-
httpc:connect("127.0.0.1", ngx.var.server_port)
71+
httpc:connect{
72+
scheme = "http",
73+
host = "127.0.0.1",
74+
port = ngx.var.server_port
75+
}
6876
6977
local res, err = httpc:request{
7078
version = 1.0,
@@ -96,7 +104,11 @@ OK
96104
content_by_lua '
97105
local http = require "resty.http"
98106
local httpc = http.new()
99-
httpc:connect("127.0.0.1", ngx.var.server_port)
107+
local ok, err = httpc:connect{
108+
scheme = "http",
109+
host = "127.0.0.1",
110+
port = ngx.var.server_port
111+
}
100112
101113
local res, err = httpc:request{
102114
path = "/b"
@@ -133,7 +145,11 @@ OK
133145
content_by_lua '
134146
local http = require "resty.http"
135147
local httpc = http.new()
136-
httpc:connect("127.0.0.1", ngx.var.server_port)
148+
httpc:connect{
149+
scheme = "http",
150+
host = "127.0.0.1",
151+
port = ngx.var.server_port
152+
}
137153
138154
local res, err = httpc:request{
139155
path = "/b"
@@ -167,7 +183,11 @@ x-value
167183
content_by_lua '
168184
local http = require "resty.http"
169185
local httpc = http.new()
170-
httpc:connect("127.0.0.1", ngx.var.server_port)
186+
httpc:connect{
187+
scheme = "http",
188+
host = "127.0.0.1",
189+
port = ngx.var.server_port
190+
}
171191
172192
local res, err = httpc:request{
173193
query = {
@@ -212,7 +232,11 @@ X-Header-B: 2
212232
content_by_lua '
213233
local http = require "resty.http"
214234
local httpc = http.new()
215-
httpc:connect("127.0.0.1", ngx.var.server_port)
235+
httpc:connect{
236+
scheme = "http",
237+
host = "127.0.0.1",
238+
port = ngx.var.server_port
239+
}
216240
217241
local res, err = httpc:request{
218242
method = "HEAD",
@@ -245,15 +269,16 @@ GET /a
245269
content_by_lua '
246270
local http = require "resty.http"
247271
248-
local res, err = http:connect("127.0.0.1", 1984)
272+
local res, err = http:connect{
273+
scheme = "http",
274+
host = "127.0.0.1",
275+
port = ngx.var.server_port
276+
}
249277
if not res then ngx.say(err) end
250278
251279
local res, err = http:set_timeout(500)
252280
if not res then ngx.say(err) end
253281
254-
local res, err = http:ssl_handshake()
255-
if not res then ngx.say(err) end
256-
257282
local res, err = http:set_keepalive()
258283
if not res then ngx.say(err) end
259284
@@ -272,7 +297,6 @@ not initialized
272297
not initialized
273298
not initialized
274299
not initialized
275-
not initialized
276300
--- no_error_log
277301
[error]
278302
[warn]
@@ -382,8 +406,11 @@ scheme: http, host: example.com, port: 80, path: /foo/bar?a=1&b=2
382406
383407
-- Create a TCP connection and return an raw HTTP-response because
384408
-- there is no way to set an empty header value in nginx.
385-
assert(httpc:connect("127.0.0.1", 12345),
386-
"connect should return positively")
409+
assert(httpc:connect{
410+
scheme = "http",
411+
host = "127.0.0.1",
412+
port = 12345,
413+
}, "connect should return positively")
387414
388415
local res = httpc:request({ path = "/b" })
389416
if res.headers["X-Header-Empty"] == "" then

t/02-chunked.t

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ __DATA__
3131
content_by_lua '
3232
local http = require "resty.http"
3333
local httpc = http.new()
34-
httpc:connect("127.0.0.1", ngx.var.server_port)
34+
httpc:connect({
35+
scheme = "http",
36+
host = "127.0.0.1",
37+
port = ngx.var.server_port
38+
})
3539
3640
local res, err = httpc:request{
3741
path = "/b"
@@ -70,7 +74,11 @@ GET /a
7074
content_by_lua '
7175
local http = require "resty.http"
7276
local httpc = http.new()
73-
httpc:connect("127.0.0.1", ngx.var.server_port)
77+
httpc:connect({
78+
scheme = "http",
79+
host = "127.0.0.1",
80+
port = ngx.var.server_port
81+
})
7482
7583
local res, err = httpc:request{
7684
path = "/b"
@@ -126,7 +134,11 @@ GET /a
126134
content_by_lua '
127135
local http = require "resty.http"
128136
local httpc = http.new()
129-
httpc:connect("127.0.0.1", ngx.var.server_port)
137+
httpc:connect({
138+
scheme = "http",
139+
host = "127.0.0.1",
140+
port = ngx.var.server_port
141+
})
130142
131143
local res, err = httpc:request{
132144
path = "/b"
@@ -170,7 +182,11 @@ GET /a
170182
content_by_lua_block {
171183
local http = require "resty.http"
172184
local httpc = http.new()
173-
httpc:connect("127.0.0.1", ngx.var.server_port)
185+
httpc:connect({
186+
scheme = "http",
187+
host = "127.0.0.1",
188+
port = ngx.var.server_port
189+
})
174190
175191
local res, err = httpc:request{
176192
path = "/b"

t/03-requestbody.t

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ __DATA__
3333
content_by_lua '
3434
local http = require "resty.http"
3535
local httpc = http.new()
36-
httpc:connect("127.0.0.1", ngx.var.server_port)
36+
httpc:connect({
37+
scheme = "http",
38+
host = "127.0.0.1",
39+
port = ngx.var.server_port
40+
})
3741
3842
local res, err = httpc:request{
3943
body = "a=1&b=2&c=3",
@@ -74,7 +78,11 @@ c: 3
7478
content_by_lua '
7579
local http = require "resty.http"
7680
local httpc = http.new()
77-
httpc:connect("127.0.0.1", ngx.var.server_port)
81+
httpc:connect({
82+
scheme = "http",
83+
host = "127.0.0.1",
84+
port = ngx.var.server_port
85+
})
7886
7987
local res, err = httpc:request{
8088
method = "POST",
@@ -119,7 +127,11 @@ c: 3
119127
content_by_lua '
120128
local http = require "resty.http"
121129
local httpc = http.new()
122-
httpc:connect("127.0.0.1", ngx.var.server_port)
130+
httpc:connect({
131+
scheme = "http",
132+
host = "127.0.0.1",
133+
port = ngx.var.server_port
134+
})
123135
124136
local res, err = httpc:request{
125137
body = "a=1&b=2&c=3",
@@ -161,7 +173,11 @@ c: 3
161173
content_by_lua '
162174
local http = require "resty.http"
163175
local httpc = http.new()
164-
httpc:connect("127.0.0.1", ngx.var.server_port)
176+
httpc:connect({
177+
scheme = "http",
178+
host = "127.0.0.1",
179+
port = ngx.var.server_port
180+
})
165181
166182
local res, err = httpc:request{
167183
path = "/b",

t/04-trailers.t

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ __DATA__
3333
content_by_lua '
3434
local http = require "resty.http"
3535
local httpc = http.new()
36-
httpc:connect("127.0.0.1", ngx.var.server_port)
36+
httpc:connect({
37+
scheme = "http",
38+
host = "127.0.0.1",
39+
port = ngx.var.server_port
40+
})
3741
3842
local res, err = httpc:request{
3943
path = "/b",
@@ -101,7 +105,11 @@ OK
101105
content_by_lua '
102106
local http = require "resty.http"
103107
local httpc = http.new()
104-
httpc:connect("127.0.0.1", ngx.var.server_port)
108+
httpc:connect({
109+
scheme = "http",
110+
host = "127.0.0.1",
111+
port = ngx.var.server_port
112+
})
105113
106114
local res, err = httpc:request{
107115
path = "/b",

t/05-stream.t

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ __DATA__
3333
content_by_lua '
3434
local http = require "resty.http"
3535
local httpc = http.new()
36-
httpc:connect("127.0.0.1", ngx.var.server_port)
36+
httpc:connect({
37+
scheme = "http",
38+
host = "127.0.0.1",
39+
port = ngx.var.server_port
40+
})
3741
3842
local res, err = httpc:request{
3943
path = "/b",
@@ -81,7 +85,11 @@ chunked
8185
content_by_lua '
8286
local http = require "resty.http"
8387
local httpc = http.new()
84-
httpc:connect("127.0.0.1", ngx.var.server_port)
88+
httpc:connect({
89+
scheme = "http",
90+
host = "127.0.0.1",
91+
port = ngx.var.server_port
92+
})
8593
8694
local res, err = httpc:request{
8795
path = "/b",
@@ -132,7 +140,11 @@ nil
132140
content_by_lua '
133141
local http = require "resty.http"
134142
local httpc = http.new()
135-
httpc:connect("127.0.0.1", ngx.var.server_port)
143+
httpc:connect({
144+
scheme = "http",
145+
host = "127.0.0.1",
146+
port = ngx.var.server_port
147+
})
136148
137149
local res, err = httpc:request{
138150
path = "/b",
@@ -181,7 +193,11 @@ Buffer size not specified, bailing
181193
content_by_lua '
182194
local http = require "resty.http"
183195
local httpc = http.new()
184-
httpc:connect("127.0.0.1", ngx.var.server_port)
196+
httpc:connect({
197+
scheme = "http",
198+
host = "127.0.0.1",
199+
port = ngx.var.server_port
200+
})
185201
186202
local res, err = httpc:request{
187203
path = "/b",
@@ -233,7 +249,11 @@ nil
233249
content_by_lua '
234250
local http = require "resty.http"
235251
local httpc = http.new()
236-
httpc:connect("127.0.0.1", ngx.var.server_port)
252+
httpc:connect({
253+
scheme = "http",
254+
host = "127.0.0.1",
255+
port = ngx.var.server_port
256+
})
237257
238258
local res, err = httpc:request{
239259
path = "/b",
@@ -287,7 +307,11 @@ nil
287307
content_by_lua '
288308
local http = require "resty.http"
289309
local httpc = http.new()
290-
httpc:connect("127.0.0.1", ngx.var.server_port)
310+
httpc:connect({
311+
scheme = "http",
312+
host = "127.0.0.1",
313+
port = ngx.var.server_port
314+
})
291315
292316
local res, err = httpc:request{
293317
path = "/b",
@@ -350,7 +374,11 @@ GET /a
350374
content_by_lua '
351375
local http = require "resty.http"
352376
local httpc = http.new()
353-
httpc:connect("127.0.0.1", ngx.var.server_port)
377+
httpc:connect({
378+
scheme = "http",
379+
host = "127.0.0.1",
380+
port = ngx.var.server_port
381+
})
354382
355383
local res, err = httpc:request{
356384
path = "/b",
@@ -466,7 +494,11 @@ foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarba
466494
content_by_lua '
467495
local http = require "resty.http"
468496
local httpc = http.new()
469-
httpc:connect("127.0.0.1", ngx.var.server_port)
497+
httpc:connect({
498+
scheme = "http",
499+
host = "127.0.0.1",
500+
port = ngx.var.server_port
501+
})
470502
471503
local reader, err = httpc:get_client_body_reader(64)
472504
@@ -509,7 +541,11 @@ foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarba
509541
content_by_lua '
510542
local http = require "resty.http"
511543
local httpc = http.new()
512-
httpc:connect("127.0.0.1", ngx.var.server_port)
544+
httpc:connect({
545+
scheme = "http",
546+
host = "127.0.0.1",
547+
port = ngx.var.server_port
548+
})
513549
514550
local res, err = httpc:request{
515551
path = "/b",

0 commit comments

Comments
 (0)