Skip to content

Commit

Permalink
test: add tests for memcached module api
Browse files Browse the repository at this point in the history
Needed for #96
  • Loading branch information
ligurio committed Feb 10, 2022
1 parent 8adc09a commit a426fd3
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/common/module_api.test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env tarantool

local socket = require('socket')
local tap = require('tap')
package.cpath = './?.so;' .. package.cpath
local memcached = require('memcached')
local test = tap.test('memcached module api')

local function is_port_open(port)
local sock, _ = socket.tcp_connect('127.0.0.1', port)
return sock:sysconnect(0, port) and true or false
end

if type(box.cfg) == 'function' then
box.cfg{
wal_mode = 'none',
memtx_memory = 100 * 1024 * 1024,
}
box.schema.user.grant('guest', 'read,write,execute', 'universe')
end

test:plan(13)

test:is(#memcached.server, 0, 'memcached.server is empty')

-- memcached.create(): instance 1

local mc_1_port = 11211
local mc_1_name = 'memcached_1_xxx'
local mc_1_space_name = 'memcached_xxx_1_space'

local mc_1 = memcached.create(mc_1_name, tostring(mc_1_port), {
space_name = mc_1_space_name
})
test:isnt(mc_1, nil, '1st memcached instance object is not nil')
test:is(is_port_open(mc_1_port), true, '1st memcached instance is started')

-- memcached.create(): instance 2

local mc_2_port = 11212
local mc_2_name = 'memcached_2_xxx'
local mc_2_space_name = 'memcached_2_xxx_space'

local mc_2 = memcached.create(mc_2_name, tostring(mc_2_port), {
space_name = mc_2_space_name
})
test:isnt(mc_2, nil, '2nd memcached instance object is not nil')
test:is(is_port_open(mc_2_port), true, '2nd memcached instance is started')

-- memcached.server

test:istable(memcached.server, 'type of memcached.server is a table')
test:is(#memcached.server, 0, 'memcached.server is empty')

-- memcached.get(): instance 1

local instance_1_info = memcached.get(mc_1_name)
test:is(instance_1_info.name, mc_1.name, 'memcached.get(): name of instance 1 is correct')
test:is(instance_1_info.space_name, mc_1.space_name, 'memcached.get(): space name of instance 1 is correct')
test:is(instance_1_info.space.id, mc_1.space.id, 'memcached.get(): space id of instance 1 is correct')

-- memcached.get(): instance 2

local instance_2_info = memcached.get(mc_2_name)
test:is(instance_2_info.name, mc_2.name, 'memcached.get(): name of instance 2 is correct')
test:is(instance_2_info.space_name, mc_2.space_name, 'memcached.get(): space name of instance 2 is correct')
test:is(instance_2_info.space.id, mc_2.space.id, 'memcached.get(): space id of instance 2 is correct')

os.exit(test:check() and 0 or 1)

0 comments on commit a426fd3

Please sign in to comment.