@@ -193,8 +193,8 @@ for _, strategy in helpers.each_strategy() do
193
193
local ok , err = db .plugins :load_plugin_schemas ({
194
194
[" plugin-with-custom-dao" ] = true ,
195
195
})
196
- assert .truthy (ok )
197
196
assert .is_nil (err )
197
+ assert .truthy (ok )
198
198
199
199
assert .same (" I was implemented for " .. strategy , db .custom_dao :custom_method ())
200
200
end )
@@ -215,12 +215,105 @@ for _, strategy in helpers.each_strategy() do
215
215
assert .match (" failed converting legacy schema for legacy-plugin-bad" , err , 1 , true )
216
216
end )
217
217
218
+ describe (" with bad PRIORITY fails; " , function ()
219
+ setup (function ()
220
+ local schema = {}
221
+ package.loaded [" kong.plugins.NaN_priority.schema" ] = schema
222
+ package.loaded [" kong.plugins.NaN_priority.handler" ] = { PRIORITY = 0 / 0 , VERSION = " 1.0" }
223
+ package.loaded [" kong.plugins.huge_negative.schema" ] = schema
224
+ package.loaded [" kong.plugins.huge_negative.handler" ] = { PRIORITY = - math.huge , VERSION = " 1.0" }
225
+ package.loaded [" kong.plugins.string_priority.schema" ] = schema
226
+ package.loaded [" kong.plugins.string_priority.handler" ] = { PRIORITY = " abc" , VERSION = " 1.0" }
227
+ end )
228
+
229
+ teardown (function ()
230
+ package.loaded [" kong.plugins.NaN_priority.schema" ] = nil
231
+ package.loaded [" kong.plugins.NaN_priority.handler" ] = nil
232
+ package.loaded [" kong.plugins.huge_negative.schema" ] = nil
233
+ package.loaded [" kong.plugins.huge_negative.handler" ] = nil
234
+ package.loaded [" kong.plugins.string_priority.schema" ] = nil
235
+ package.loaded [" kong.plugins.string_priority.handler" ] = nil
236
+ end )
237
+
238
+ it (" NaN" , function ()
239
+ local ok , err = db .plugins :load_plugin_schemas ({
240
+ [" NaN_priority" ] = true ,
241
+ })
242
+ assert .falsy (ok )
243
+ assert .match (' Plugin "NaN_priority" cannot be loaded because its PRIORITY field is not a valid integer number, got: "nan"' , err , 1 , true )
244
+ end )
245
+
246
+ it (" -math.huge" , function ()
247
+ local ok , err = db .plugins :load_plugin_schemas ({
248
+ [" huge_negative" ] = true ,
249
+ })
250
+ assert .falsy (ok )
251
+ assert .match (' Plugin "huge_negative" cannot be loaded because its PRIORITY field is not a valid integer number, got: "-inf"' , err , 1 , true )
252
+ end )
253
+
254
+ it (" string" , function ()
255
+ local ok , err = db .plugins :load_plugin_schemas ({
256
+ [" string_priority" ] = true ,
257
+ })
258
+ assert .falsy (ok )
259
+ assert .match (' Plugin "string_priority" cannot be loaded because its PRIORITY field is not a valid integer number, got: "abc"' , err , 1 , true )
260
+ end )
261
+
262
+ end )
263
+
264
+ describe (" with bad VERSION fails; " , function ()
265
+ setup (function ()
266
+ local schema = {}
267
+ package.loaded [" kong.plugins.no_version.schema" ] = schema
268
+ package.loaded [" kong.plugins.no_version.handler" ] = { PRIORITY = 1000 , VERSION = nil }
269
+ package.loaded [" kong.plugins.too_many.schema" ] = schema
270
+ package.loaded [" kong.plugins.too_many.handler" ] = { PRIORITY = 1000 , VERSION = " 1.0.0.0" }
271
+ package.loaded [" kong.plugins.number.schema" ] = schema
272
+ package.loaded [" kong.plugins.number.handler" ] = { PRIORITY = 1000 , VERSION = 123 }
273
+ end )
274
+
275
+ teardown (function ()
276
+ package.loaded [" kong.plugins.no_version.schema" ] = nil
277
+ package.loaded [" kong.plugins.no_version.handler" ] = nil
278
+ package.loaded [" kong.plugins.too_many.schema" ] = nil
279
+ package.loaded [" kong.plugins.too_many.handler" ] = nil
280
+ package.loaded [" kong.plugins.number.schema" ] = nil
281
+ package.loaded [" kong.plugins.number.handler" ] = nil
282
+ end )
283
+
284
+ it (" without version" , function ()
285
+ local ok , err = db .plugins :load_plugin_schemas ({
286
+ [" no_version" ] = true ,
287
+ })
288
+ assert .falsy (ok )
289
+ assert .match (' Plugin "no_version" cannot be loaded because its VERSION field does not follow the "x.y.z" format, got: "nil"' , err , 1 , true )
290
+ end )
291
+
292
+ it (" too many components" , function ()
293
+ local ok , err = db .plugins :load_plugin_schemas ({
294
+ [" too_many" ] = true ,
295
+ })
296
+ assert .falsy (ok )
297
+ assert .match (' Plugin "too_many" cannot be loaded because its VERSION field does not follow the "x.y.z" format, got: "1.0.0.0"' , err , 1 , true )
298
+ end )
299
+
300
+ it (" number" , function ()
301
+ local ok , err = db .plugins :load_plugin_schemas ({
302
+ [" number" ] = true ,
303
+ })
304
+ assert .falsy (ok )
305
+ assert .match (' Plugin "number" cannot be loaded because its VERSION field does not follow the "x.y.z" format, got: "123"' , err , 1 , true )
306
+ end )
307
+
308
+ end )
309
+
310
+
218
311
it (" succeeds with good plugins" , function ()
219
312
local ok , err = db .plugins :load_plugin_schemas ({
220
313
[" legacy-plugin-good" ] = true ,
221
314
})
222
- assert .truthy (ok )
223
315
assert .is_nil (err )
316
+ assert .truthy (ok )
224
317
225
318
local foo = {
226
319
required = false ,
0 commit comments