Skip to content

Commit 28a6183

Browse files
flrghwindmgc
authored andcommitted
chore(lint): fix remaining helpers-outside-of-setup warnings
This is a follow-up to d1a8e41 that fixes the remainder of the files with warnings. ``` $ ast-grep scan | wc -l 0 ```
1 parent e38217c commit 28a6183

File tree

8 files changed

+251
-147
lines changed

8 files changed

+251
-147
lines changed

spec/02-integration/04-admin_api/21-admin-api-keys_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ local KEY_SET_NAME = "test"
88
for _, strategy in helpers.all_strategies() do
99
describe("Admin API - keys #" .. strategy, function()
1010
local pem_pub, pem_priv, jwk
11-
helpers.setenv("SECRET_JWK", '{"alg": "RSA-OAEP", "kid": "test"}')
1211
local client
1312
lazy_setup(function()
13+
helpers.setenv("SECRET_JWK", '{"alg": "RSA-OAEP", "kid": "test"}')
1414
helpers.get_db_utils(strategy, {
1515
"keys",
1616
"key_sets"})

spec/02-integration/05-proxy/10-balancer/02-least-connections_spec.lua

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ local helpers = require "spec.helpers"
44
local https_server = helpers.https_server
55

66

7-
local test_port1 = helpers.get_available_port()
8-
local test_port2 = helpers.get_available_port()
9-
10-
11-
-- create two servers, one double the delay of the other
12-
local server1 = https_server.new(test_port1, "127.0.0.1", "http", false, nil, 100)
13-
local server2 = https_server.new(test_port2, "127.0.0.1", "http", false, nil, 200)
14-
157
for _, strategy in helpers.each_strategy() do
168
describe("Balancer: least-connections [#" .. strategy .. "]", function()
179
local upstream1_id
1810

11+
local test_port1
12+
local test_port2
13+
14+
local server1
15+
local server2
16+
1917
lazy_setup(function()
18+
test_port1 = helpers.get_available_port()
19+
test_port2 = helpers.get_available_port()
20+
21+
-- create two servers, one double the delay of the other
22+
server1 = https_server.new(test_port1, "127.0.0.1", "http", false, nil, 100)
23+
server2 = https_server.new(test_port2, "127.0.0.1", "http", false, nil, 200)
24+
2025
local bp = helpers.get_db_utils(strategy, {
2126
"routes",
2227
"services",
@@ -214,13 +219,17 @@ for _, strategy in helpers.each_strategy() do
214219

215220
local api_client = helpers.admin_client()
216221

222+
-- we never send a request to this upstream, so just pick a random
223+
-- port number for testing
224+
local test_port = math.random(1000, 9000)
225+
217226
-- create a new target
218227
local res = assert(api_client:post("/upstreams/" .. an_upstream.id .. "/targets", {
219228
headers = {
220229
["Content-Type"] = "application/json",
221230
},
222231
body = {
223-
target = "127.0.0.1:" .. test_port1,
232+
target = "127.0.0.1:" .. test_port,
224233
weight = 100
225234
},
226235
}))
@@ -239,7 +248,7 @@ for _, strategy in helpers.each_strategy() do
239248
api_client:close()
240249
local found = false
241250
for _, entry in ipairs(body.data) do
242-
if entry.target == "127.0.0.1:" .. test_port1 and entry.weight == 100 then
251+
if entry.target == "127.0.0.1:" .. test_port and entry.weight == 100 then
243252
found = true
244253
break
245254
end
@@ -250,7 +259,7 @@ for _, strategy in helpers.each_strategy() do
250259
api_client = helpers.admin_client()
251260
res, err = api_client:send({
252261
method = "DELETE",
253-
path = "/upstreams/" .. an_upstream.id .. "/targets/127.0.0.1:" .. test_port1,
262+
path = "/upstreams/" .. an_upstream.id .. "/targets/127.0.0.1:" .. test_port,
254263
})
255264
assert.is_nil(err)
256265
assert.same(204, res.status)
@@ -267,7 +276,7 @@ for _, strategy in helpers.each_strategy() do
267276
api_client:close()
268277
local found = false
269278
for _, entry in ipairs(body.data) do
270-
if entry.target == "127.0.0.1:" .. test_port1 and entry.weight == 0 then
279+
if entry.target == "127.0.0.1:" .. test_port and entry.weight == 0 then
271280
found = true
272281
break
273282
end

spec/02-integration/05-proxy/10-balancer/07-latency_spec.lua

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@ local helpers = require "spec.helpers"
44
local https_server = helpers.https_server
55

66

7-
local test_port1 = helpers.get_available_port()
8-
local test_port2 = helpers.get_available_port()
9-
10-
11-
-- create two servers, one double the delay of the other
12-
local server1 = https_server.new(test_port1, "127.0.0.1", "http", false, nil, 100)
13-
local server2 = https_server.new(test_port2, "127.0.0.1", "http", false, nil, 1000)
14-
157
for _, strategy in helpers.each_strategy() do
168
describe("Balancer: latency [#" .. strategy .. "]", function()
179
local upstream1_id
1810

11+
local test_port1
12+
local test_port2
13+
local server1
14+
local server2
15+
1916
lazy_setup(function()
17+
test_port1 = helpers.get_available_port()
18+
test_port2 = helpers.get_available_port()
19+
20+
-- create two servers, one double the delay of the other
21+
server1 = https_server.new(test_port1, "127.0.0.1", "http", false, nil, 100)
22+
server2 = https_server.new(test_port2, "127.0.0.1", "http", false, nil, 1000)
23+
2024
local bp = helpers.get_db_utils(strategy, {
2125
"routes",
2226
"services",
@@ -227,13 +231,17 @@ for _, strategy in helpers.each_strategy() do
227231

228232
local api_client = helpers.admin_client()
229233

234+
-- we never send a request to this upstream, so just pick a random
235+
-- port number for testing
236+
local test_port = math.random(1000, 9000)
237+
230238
-- create a new target
231239
local res = assert(api_client:post("/upstreams/" .. an_upstream.id .. "/targets", {
232240
headers = {
233241
["Content-Type"] = "application/json",
234242
},
235243
body = {
236-
target = "127.0.0.1:" .. test_port1,
244+
target = "127.0.0.1:" .. test_port,
237245
weight = 100
238246
},
239247
}))
@@ -252,7 +260,7 @@ for _, strategy in helpers.each_strategy() do
252260
api_client:close()
253261
local found = false
254262
for _, entry in ipairs(body.data) do
255-
if entry.target == "127.0.0.1:" .. test_port1 and entry.weight == 100 then
263+
if entry.target == "127.0.0.1:" .. test_port and entry.weight == 100 then
256264
found = true
257265
break
258266
end
@@ -263,7 +271,7 @@ for _, strategy in helpers.each_strategy() do
263271
api_client = helpers.admin_client()
264272
res, err = api_client:send({
265273
method = "DELETE",
266-
path = "/upstreams/" .. an_upstream.id .. "/targets/127.0.0.1:" .. test_port1,
274+
path = "/upstreams/" .. an_upstream.id .. "/targets/127.0.0.1:" .. test_port,
267275
})
268276
assert.is_nil(err)
269277
assert.same(204, res.status)
@@ -280,7 +288,7 @@ for _, strategy in helpers.each_strategy() do
280288
api_client:close()
281289
local found = false
282290
for _, entry in ipairs(body.data) do
283-
if entry.target == "127.0.0.1:" .. test_port1 and entry.weight == 0 then
291+
if entry.target == "127.0.0.1:" .. test_port and entry.weight == 0 then
284292
found = true
285293
break
286294
end

spec/02-integration/08-status_api/05-dns_client_spec.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
local helpers = require "spec.helpers"
22
local cjson = require "cjson"
33

4-
local tcp_status_port = helpers.get_available_port()
5-
64
for _, strategy in helpers.each_strategy() do
75
describe("[#traditional] Status API - DNS client route with [#" .. strategy .. "]" , function()
86
local client
7+
local tcp_status_port
98

109
lazy_setup(function()
10+
tcp_status_port = helpers.get_available_port()
11+
1112
local bp = helpers.get_db_utils(strategy, {
1213
"upstreams",
1314
"targets",
@@ -69,7 +70,11 @@ for _, strategy in helpers.each_strategy() do
6970
describe("[#traditional] Status API - DNS client route with [#" .. strategy .. "]" , function()
7071
local client
7172

73+
local tcp_status_port
74+
7275
lazy_setup(function()
76+
tcp_status_port = helpers.get_available_port()
77+
7378
helpers.get_db_utils(strategy)
7479

7580
assert(helpers.start_kong({
@@ -110,7 +115,11 @@ for _, strategy in helpers.each_strategy() do
110115
describe("[#hybrid] Status API - DNS client route with [#" .. strategy .. "]" , function()
111116
local client
112117

118+
local tcp_status_port
119+
113120
lazy_setup(function()
121+
tcp_status_port = helpers.get_available_port()
122+
114123
helpers.get_db_utils(strategy) -- runs migrations
115124

116125
assert(helpers.start_kong({

0 commit comments

Comments
 (0)