Skip to content

Commit

Permalink
template: proper test group usage
Browse files Browse the repository at this point in the history
Test group entity is passed to each hook/test. Legacy approach is to use
group as global variable, which should work for simple groups, but is
invalid for parametrized ones. `cg` variable name was borrowed from
luatest README (it is likely a "current group" abbreviation).
  • Loading branch information
DifferentialOrange committed May 26, 2023
1 parent 6919a1c commit 5b20b1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions cli/create/templates/cartridge/test/integration/api_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@ local t = require('luatest')
local g = t.group('integration_api')

local helper = require('test.helper')
local cluster = helper.cluster

g.before_all(function()
g.cluster = helper.cluster
g.cluster:start()
g.before_all(function(cg)
cg.cluster = helper.cluster
cg.cluster:start()
end)

g.after_all(function()
helper.stop_cluster(g.cluster)
g.after_all(function(cg)
helper.stop_cluster(cg.cluster)
end)

g.before_each(function()
g.before_each(function(cg)
-- helper.truncate_space_on_cluster(g.cluster, 'Set your space name here')
end)

g.test_sample = function()
local server = cluster.main_server
g.test_sample = function(cg)
local server = cg.cluster.main_server
local response = server:http_request('post', '/admin/api', {json = {query = '{ cluster { self { alias } } }'}})
t.assert_equals(response.json, {data = { cluster = { self = { alias = 'api' } } }})
t.assert_equals(server.net_box:eval('return box.cfg.memtx_dir'), server.workdir)
end

g.test_metrics = function()
local server = cluster.main_server
g.test_metrics = function(cg)
local server = cg.cluster.main_server
local response = server:http_request('get', '/metrics')
t.assert_equals(response.status, 200)
t.assert_equals(response.reason, "Ok")
Expand Down
6 changes: 3 additions & 3 deletions cli/create/templates/cartridge/test/unit/sample_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('unit_sample')

-- create your space here
g.before_all(function() end)
g.before_all(function(cg) end)

-- drop your space here
g.after_all(function() end)
g.after_all(function(cg) end)

g.test_sample = function()
g.test_sample = function(cg)
t.assert_equals(type(box.cfg), 'table')
end

0 comments on commit 5b20b1e

Please sign in to comment.