Skip to content

Commit de8ceea

Browse files
committed
Restructure negative limit tests
1 parent 1858d8a commit de8ceea

File tree

1 file changed

+68
-20
lines changed

1 file changed

+68
-20
lines changed

test/integration/select_test.lua

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -262,28 +262,28 @@ add('test_negative_first', function(g)
262262
local customers = insert_customers(g, {
263263
{
264264
id = 1, name = "Elizabeth", last_name = "Jackson",
265-
age = 12, city = "New York",
265+
age = 11, city = "New York",
266266
}, {
267267
id = 2, name = "Mary", last_name = "Brown",
268-
age = 46, city = "Los Angeles",
268+
age = 22, city = "Los Angeles",
269269
}, {
270270
id = 3, name = "David", last_name = "Smith",
271271
age = 33, city = "Los Angeles",
272272
}, {
273273
id = 4, name = "William", last_name = "White",
274-
age = 81, city = "Chicago",
274+
age = 44, city = "Chicago",
275275
}, {
276276
id = 5, name = "Jack", last_name = "Sparrow",
277-
age = 35, city = "London",
277+
age = 55, city = "London",
278278
}, {
279279
id = 6, name = "William", last_name = "Terner",
280-
age = 25, city = "Oxford",
280+
age = 66, city = "Oxford",
281281
}, {
282282
id = 7, name = "Elizabeth", last_name = "Swan",
283-
age = 18, city = "Cambridge",
283+
age = 77, city = "Cambridge",
284284
}, {
285285
id = 8, name = "Hector", last_name = "Barbossa",
286-
age = 45, city = "London",
286+
age = 88, city = "London",
287287
},
288288
})
289289

@@ -327,14 +327,13 @@ add('test_negative_first', function(g)
327327
local objects = crud.unflatten_rows(result.rows, result.metadata)
328328
t.assert_equals(objects, get_by_ids(customers, {2, 3, 4}))
329329

330-
-- age <= 33 (eq for id: 3)
331-
-- (in sorted by age order: 4, 2, 8, 5, 3, 6, 7, 1)
332-
-- first -2 after 7 (batch_size is 1)
330+
-- id >= 2
331+
-- first -2 after 5 (batch_size is 1)
333332
local conditions = {
334-
{'<=', 'age', 33},
333+
{'>=', 'id', 2},
335334
}
336335
local first = -2
337-
local after = customers[7]
336+
local after = customers[5]
338337
local batch_size = 1
339338
local result, err = g.cluster.main_server.net_box:eval([[
340339
local crud = require('crud')
@@ -351,17 +350,40 @@ add('test_negative_first', function(g)
351350

352351
t.assert_equals(err, nil)
353352
local objects = crud.unflatten_rows(result.rows, result.metadata)
354-
t.assert_equals(objects, get_by_ids(customers, {3, 6}))
353+
t.assert_equals(objects, get_by_ids(customers, {3, 4}))
355354

356-
-- after is out of border
357-
-- age <= 33 (eq for id: 3)
358-
-- (in sorted by age order: 4, 2, 8, 5, 3, 6, 7, 1)
359-
-- first -2 after 3 (batch_size is 1)
355+
-- age >= 22
356+
-- first -2 after 5 (batch_size is 1)
360357
local conditions = {
361-
{'<=', 'age', 33},
358+
{'>=', 'age', 22},
362359
}
363360
local first = -2
364-
local after = customers[3]
361+
local after = customers[5]
362+
local batch_size = 1
363+
local result, err = g.cluster.main_server.net_box:eval([[
364+
local crud = require('crud')
365+
366+
local conditions, first, after, batch_size = ...
367+
368+
local objects, err = crud.select('customers', conditions, {
369+
first = first,
370+
after = after,
371+
batch_size = batch_size,
372+
})
373+
return objects, err
374+
]], {conditions, first, after, batch_size})
375+
376+
t.assert_equals(err, nil)
377+
local objects = crud.unflatten_rows(result.rows, result.metadata)
378+
t.assert_equals(objects, get_by_ids(customers, {3, 4}))
379+
380+
-- id <= 6
381+
-- first -2 after 5 (batch_size is 1)
382+
local conditions = {
383+
{'<=', 'id', 6},
384+
}
385+
local first = -2
386+
local after = customers[5]
365387
local batch_size = 1
366388
local result, err = g.cluster.main_server.net_box:eval([[
367389
local crud = require('crud')
@@ -377,7 +399,33 @@ add('test_negative_first', function(g)
377399
]], {conditions, first, after, batch_size})
378400

379401
t.assert_equals(err, nil)
380-
t.assert_equals(#result.rows, 0)
402+
local objects = crud.unflatten_rows(result.rows, result.metadata)
403+
t.assert_equals(objects, get_by_ids(customers, {6}))
404+
405+
-- age <= 66
406+
-- first -2 after 5 (batch_size is 1)
407+
local conditions = {
408+
{'<=', 'age', 66},
409+
}
410+
local first = -2
411+
local after = customers[5]
412+
local batch_size = 1
413+
local result, err = g.cluster.main_server.net_box:eval([[
414+
local crud = require('crud')
415+
416+
local conditions, first, after, batch_size = ...
417+
418+
local objects, err = crud.select('customers', conditions, {
419+
first = first,
420+
after = after,
421+
batch_size = batch_size,
422+
})
423+
return objects, err
424+
]], {conditions, first, after, batch_size})
425+
426+
t.assert_equals(err, nil)
427+
local objects = crud.unflatten_rows(result.rows, result.metadata)
428+
t.assert_equals(objects, get_by_ids(customers, {6}))
381429
end)
382430

383431
add('test_select_all_with_batch_size', function(g)

0 commit comments

Comments
 (0)