Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 02c2c81

Browse files
committed
find_index: add basic unit test
1 parent 67f217d commit 02c2c81

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

test/unit/find_index.test.lua

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env tarantool
2+
3+
local tap = require('tap')
4+
local fio = require('fio')
5+
6+
-- require in-repo version of graphql/ sources despite current working directory
7+
local cur_dir = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
8+
:gsub('/./', '/'):gsub('/+$', ''))
9+
package.path =
10+
cur_dir .. '/../../?/init.lua' .. ';' ..
11+
cur_dir .. '/../../?.lua' .. ';' ..
12+
package.path
13+
14+
local find_index = require('graphql.find_index')
15+
local testdata = require('test.testdata.common_testdata')
16+
17+
local cases = {
18+
{
19+
name = 'find one-part index',
20+
collection_name = 'user_collection',
21+
from = {
22+
collection_name = nil,
23+
connection_name = 'user_collection',
24+
destination_args_names = {},
25+
destination_args_values = {},
26+
},
27+
filter = {user_id = 'user_id_1'},
28+
args = {},
29+
exp_full_match = true,
30+
exp_index_name = 'user_id_index',
31+
exp_filter = {},
32+
exp_index_value = {'user_id_1'},
33+
exp_pivot = nil,
34+
},
35+
}
36+
37+
local test = tap.test('find_index')
38+
test:plan(#cases)
39+
40+
local db_schema = testdata.meta or testdata.get_test_metadata()
41+
local index_finder = find_index.new(db_schema)
42+
43+
local function run_case(test, index_finder, case)
44+
local full_match, index_name, filter, index_value, pivot =
45+
index_finder:find(case.collection_name, case.from, case.filter,
46+
case.args)
47+
local res = {
48+
full_match = full_match,
49+
index_name = index_name,
50+
filter = filter,
51+
index_value = index_value,
52+
pivot = pivot,
53+
}
54+
local exp = {
55+
full_match = case.exp_full_match,
56+
index_name = case.exp_index_name,
57+
filter = case.exp_filter,
58+
index_value = case.exp_index_value,
59+
pivot = case.exp_pivot,
60+
}
61+
test:is_deeply(res, exp, case.name)
62+
end
63+
64+
for _, case in ipairs(cases) do
65+
run_case(test, index_finder, case)
66+
end
67+
68+
os.exit(test:check() == true and 0 or 1)

0 commit comments

Comments
 (0)