Skip to content

Commit

Permalink
run tests using github actions
Browse files Browse the repository at this point in the history
 - Drop dependency from "cartridge" parse function in tests
 - Add Github Actions test workflow
  • Loading branch information
olegrok committed Dec 30, 2020
1 parent 4f43104 commit ce0cca2
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 48 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/test_on_push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Run tests

on:
push:
pull_request:

jobs:
run-tests-ce:
if: |
github.event_name == 'push' ||
github.event_name == 'pull_request' && github.event.pull_request.head.repo.owner.login != 'tarantool'
strategy:
matrix:
tarantool: ["1.10", "2.6", "2.7"]
fail-fast: false
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: tarantool/setup-tarantool@v1
with:
tarantool-version: ${{ matrix.tarantool }}

- name: Build module
run: |
tarantoolctl rocks make
- name: Run linter
run: |
tarantoolctl rocks install luacheck 0.25.0
.rocks/bin/luacheck .
- name: Run tests
run: |
git clone https://github.com/bjornbytes/graphql-lua
sed -i 's/lpeg/lulpeg/g' graphql-lua/graphql-0.0.2-1.rockspec
sed -i "s/local lpeg = require 'lpeg'/local lpeg = require 'lulpeg'/g" graphql-lua/graphql/parse.lua
tarantoolctl rocks make --chdir graphql-lua
tarantoolctl rocks install luatest 0.5.2
.rocks/bin/luatest -v
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ CTestTestfile.cmake
Testing
cmake-build-debug/
build.luarocks/
.idea/
.idea/
.rocks/
graphql-lua
15 changes: 15 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
redefined = false
std = {
read_globals = {
'require', 'debug', 'pcall', 'xpcall', 'tostring',
'tonumber', 'type', 'assert', 'ipairs', 'math', 'error', 'string',
'table', 'pairs', 'os', 'io', 'select', 'unpack', 'dofile', 'next',
'loadstring', 'setfenv', 'utf8', 'tonumber64', 'print', 'load',
'rawget', 'rawset', 'getmetatable', 'setmetatable', '_G', 'jit',
'collectgarbage',
},
}
globals = {'box', 'utf8'}
include_files = {'**/*.lua', '*.luacheckrc', '*.rockspec'}
exclude_files = {'**/*.rocks/', 'graphql-lua/'}
max_line_length = 120
6 changes: 6 additions & 0 deletions benchmarks/benchmark2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ local function test_perf(folder, iterations)
folder = fio.pathjoin(debug.sourcedir(), folder)
if fio.path.is_dir(folder) then
local files_list, err = fio.glob(fio.pathjoin(folder, '*.graphql'))
if err ~= nil then
error(err)
end
if files_list then
for _, file in ipairs(files_list) do
local item = {
Expand Down Expand Up @@ -78,6 +81,9 @@ local function test_perf(folder, iterations)
for _ = 1, iterations do
start = clock.monotonic64()
vanilla_parse, err = Parse_Error:pcall(parse.parse, request.request)
if err ~= nil then
error(err)
end
duration = clock.monotonic64() - start
if vanilla_parse then
requests[index].vanilla = requests[index].vanilla + tonumber(duration)
Expand Down
32 changes: 32 additions & 0 deletions luagraphqlparser-0.1.0-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package = 'luagraphqlparser'
version = '0.1.0-1'

source = {
url = 'git://github.com/tarantool/luagraphqlparser.git';
tag = '0.1.0';
}

description = {
summary = "Lua graphql parser";
detailed = [[
Lua port of libgraphqlparser
]];
homepage = 'https://github.com/tarantool/luagraphqlparser.git';
maintainer = "Oleg Babin <[email protected]>";
license = 'BSD2';
}

dependencies = {
'lua == 5.1';
}

build = {
type = 'cmake';
variables = {
CMAKE_BUILD_TYPE="RelWithDebInfo";
TARANTOOL_DIR="$(TARANTOOL_DIR)";
TARANTOOL_INSTALL_LIBDIR="$(LIBDIR)";
TARANTOOL_INSTALL_LUADIR="$(LUADIR)";
};
}
-- vim: syntax=lua ts=4 sts=4 sw=4 et
6 changes: 3 additions & 3 deletions test/definitions_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ local t = require('luatest')
local g = t.group()

local parse = require('luagraphqlparser').parse
local cartridge_parse = require('cartridge.graphql.parse').parse
local luagraphql_parse = require('graphql.parse')

function g.test_several_definitions()
local query = [[
query { test(a: 123) }
mutation { test(a: 123) }
mutation { test2(a: 123) }
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_several_definitions_with_aliases()
Expand All @@ -19,5 +19,5 @@ function g.test_several_definitions_with_aliases()
mutation { test(a: 123) }
mutation { a3: test2(a: 123) }
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end
14 changes: 7 additions & 7 deletions test/directives_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ local t = require('luatest')
local g = t.group()

local parse = require('luagraphqlparser').parse
local cartridge_parse = require('cartridge.graphql.parse').parse
local luagraphql_parse = require('graphql.parse')

function g.test_field()
local query = [[ query { friends @include(if: $withFriends) } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_subselections()
Expand All @@ -16,23 +16,23 @@ function g.test_subselections()
friends2 @include(if: $withFriends val: 2) @exclude { name { v } }
}
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_in_operation_definition()
local query = [[ query @someRandomDirective { op } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_in_fragment_spread()
local query = [[ {...a@skip} ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_in_inline_fragment_spread()
local query = [[ {...on a@skip { a }} ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))

local query = [[ {...{a}} ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end
18 changes: 9 additions & 9 deletions test/fragment_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ local t = require('luatest')
local g = t.group()

local parse = require('luagraphqlparser').parse
local cartridge_parse = require('cartridge.graphql.parse').parse
local luagraphql_parse = require('graphql.parse')

function g.test_simple_fragment_definition()
local query = [[
fragment f on Obj { k }
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_simple_fragment_definition_with_alias()
local query = [[
fragment f on Obj { a: k }
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_fragment_definition()
Expand All @@ -25,14 +25,14 @@ function g.test_fragment_definition()
value { nested_obj { nested_field } }
}
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_fragment_spread()
local query = [[
{ query { ...spread } }
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_fragment_complex()
Expand All @@ -54,7 +54,7 @@ function g.test_fragment_complex()
}
}
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_fragment_with_variables()
Expand All @@ -80,12 +80,12 @@ function g.test_fragment_with_variables()
}
}
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_fragment_inline_simple()
local query = [[ { value { ... on Human { height } } } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_fragment_inline_complex()
Expand All @@ -102,5 +102,5 @@ function g.test_fragment_inline_complex()
}
}
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end
8 changes: 4 additions & 4 deletions test/misc_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local t = require('luatest')
local g = t.group()

local parse = require('luagraphqlparser').parse
local cartridge_parse = require('cartridge.graphql.parse').parse
local luagraphql_parse = require('graphql.parse')

function g.test_operation_name()
local query = [[
Expand All @@ -15,7 +15,7 @@ function g.test_operation_name()
}
}
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_comment()
Expand All @@ -30,7 +30,7 @@ function g.test_comment()
}
# Comment
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_metafields()
Expand All @@ -50,5 +50,5 @@ function g.test_metafields()
}
}
]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end
6 changes: 3 additions & 3 deletions test/selections_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ local t = require('luatest')
local g = t.group()

local parse = require('luagraphqlparser').parse
local cartridge_parse = require('cartridge.graphql.parse').parse
local luagraphql_parse = require('graphql.parse')

function g.test_select_field()
local query = [[ { test { a } } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_select_set()
local query = [[ { test { a { b { c d } e } } } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end
24 changes: 12 additions & 12 deletions test/values_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ local t = require('luatest')
local g = t.group()

local parse = require('luagraphqlparser').parse
local cartridge_parse = require('cartridge.graphql.parse').parse
local luagraphql_parse = require('graphql.parse')

function g.test_int()
local query = [[ query { test(a: 123) } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_bool()
local query = [[ query { test(a: bool) } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_float()
local query = [[ query { test(a: 2.5) } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_enum()
local query = [[ query { test(a: en) } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_string()
local query = [[ query { test(a: "str") } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_null()
Expand Down Expand Up @@ -61,27 +61,27 @@ end

function g.test_empty_list()
local query = [[ query { test(a: []) } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_list_simple()
local query = [[ query { test(a: [1, "a", 2.5, false]) } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_empty_object()
local query = [[ query { test(a: {}) } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_object_simple()
local query = [[ query { test(a: {i: 1 f: 2.5 s: "s" e: en b: true}) } ]]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_nesting()
local query = [==[ query { test(a: {l: [1, 2, {c: [true, false, {c: {d: {e: 5}}}]}, [1]]}) } ]==]
t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end

function g.test_value_with_slash()
Expand Down Expand Up @@ -123,5 +123,5 @@ function g.test_example()
}
]]

t.assert_equals(parse(query), cartridge_parse(query))
t.assert_equals(parse(query), luagraphql_parse(query))
end
Loading

0 comments on commit ce0cca2

Please sign in to comment.