Change-Id: I1a5c4cb887276c363ba1158ec72525c70dc17901changes/39/39339/1
parent
dc1ba69f3f
commit
2b57bbe5bb
@ -1,2 +1,2 @@
|
||||
globals = {'sr', '_ENV'}
|
||||
globals = {'KSR', '_ENV'}
|
||||
ignore = { '212' }
|
||||
|
@ -1,56 +0,0 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
|
||||
local logging = require ('logging')
|
||||
local log_file = require ('logging.file')
|
||||
local lemock = require ('lemock')
|
||||
|
||||
local hdrMock = require 'mocks.hdr'
|
||||
local pvMock = require 'mocks.pv'
|
||||
local xavpMock = require 'mocks.xavp'
|
||||
|
||||
-- class srMock
|
||||
local srMock = {
|
||||
__class__ = 'srMock',
|
||||
_logger = log_file("reports/sr_%s.log", "%Y-%m-%d"),
|
||||
_logger_levels = {
|
||||
dbg = logging.DEBUG,
|
||||
info = logging.INFO,
|
||||
warn = logging.WARN,
|
||||
err = logging.ERROR,
|
||||
crit = logging.FATAL
|
||||
}
|
||||
}
|
||||
local srMock_MT = { __index = srMock, __newindex = lemock.controller():mock() }
|
||||
function srMock.new(ksr)
|
||||
local t = {}
|
||||
t.hdr = ksr.hdr
|
||||
t.pv = ksr.pv
|
||||
function t.log(level, message)
|
||||
if not t._logger_levels[level] then
|
||||
error(string.format("level %s unknown", tostring(level)))
|
||||
end
|
||||
t._logger:log(t._logger_levels[level], message)
|
||||
end
|
||||
t.xavp = xavpMock.new(t.pv)
|
||||
setmetatable(t, srMock_MT)
|
||||
return t
|
||||
end
|
||||
-- end class
|
||||
return srMock
|
@ -1,83 +0,0 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
|
||||
local logging = require ('logging')
|
||||
local log_file = require ('logging.file')
|
||||
|
||||
-- class xavpMock
|
||||
local xavpMock = {
|
||||
__class__ = 'xavpMock',
|
||||
_logger = log_file("reports/xavp_%s.log", "%Y-%m-%d"),
|
||||
_logger_levels = {
|
||||
dbg = logging.DEBUG,
|
||||
info = logging.INFO,
|
||||
warn = logging.WARN,
|
||||
err = logging.ERROR,
|
||||
crit = logging.FATAL
|
||||
}
|
||||
}
|
||||
function xavpMock.new(pv)
|
||||
local t = {}
|
||||
|
||||
t.__class__ = 'xavpMock'
|
||||
t.pv = pv
|
||||
|
||||
function t._get_xavp(xavp_name, index, mode)
|
||||
local private_id = "xavp:" .. xavp_name
|
||||
local temp = {}
|
||||
if not t.pv.vars[private_id] then
|
||||
error(string.format("%s not found", xavp_name))
|
||||
elseif not t.pv.vars[private_id][index] then
|
||||
error(string.format("%s[%s] not found",
|
||||
xavp_name, tostring(index)))
|
||||
end
|
||||
if mode == 0 then
|
||||
for k,v in pairs(t.pv.vars[private_id][index]) do
|
||||
temp[k] = v:list()
|
||||
end
|
||||
else
|
||||
for k,v in pairs(t.pv.vars[private_id][index]) do
|
||||
temp[k] = v[0]
|
||||
end
|
||||
end
|
||||
return temp
|
||||
end
|
||||
|
||||
function t.get_keys(xavp_name, index)
|
||||
local output = {}
|
||||
|
||||
local xavp = t._get_xavp(xavp_name, index, 1)
|
||||
for k,_ in pairs(xavp) do
|
||||
table.insert(output, k)
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
function t.get(xavp_name, index, mode)
|
||||
if not mode then mode = 0 end
|
||||
local xavp = t._get_xavp(xavp_name, index, mode)
|
||||
return xavp
|
||||
end
|
||||
|
||||
local xavpMock_MT = { __index = xavpMock }
|
||||
setmetatable(t, xavpMock_MT)
|
||||
return t
|
||||
end
|
||||
--end class
|
||||
return xavpMock
|
@ -1,3 +1,3 @@
|
||||
globals = {'KSR', 'sr'}
|
||||
globals = {'KSR'}
|
||||
-- until we fix the luaunit new format at run_tests.sh
|
||||
ignore = {'assert.*', '212'}
|
||||
|
@ -1,68 +0,0 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
--
|
||||
|
||||
require('luaunit')
|
||||
local ksrMock = require 'mocks.ksr'
|
||||
local srMock = require 'mocks.sr'
|
||||
|
||||
-- luacheck: ignore TestSRMock
|
||||
TestSRMock = {}
|
||||
function TestSRMock:setUp()
|
||||
self.ksr = ksrMock.new()
|
||||
self.sr = srMock.new(self.ksr)
|
||||
end
|
||||
|
||||
function TestSRMock:test_hdr()
|
||||
assertIs(self.sr.hdr, self.ksr.hdr)
|
||||
end
|
||||
|
||||
function TestSRMock:test_hdr_get()
|
||||
self.sr.hdr.insert("From: hola\r\n")
|
||||
assertEquals(self.sr.hdr.headers, {"From: hola\r\n"})
|
||||
assertEquals(self.sr.pv.get("$hdr(From)"), "hola")
|
||||
end
|
||||
|
||||
function TestSRMock:test_pv()
|
||||
self.sr.pv.sets("$var(test)", "value")
|
||||
assertEquals(self.sr.pv.get("$var(test)"), "value")
|
||||
assertIs(self.sr.pv, self.ksr.pv)
|
||||
end
|
||||
|
||||
function TestSRMock:test_pv_get()
|
||||
assertIs(self.sr.pv, self.ksr.pv)
|
||||
end
|
||||
|
||||
function TestSRMock:test_log()
|
||||
assertNotNil(self.sr.log)
|
||||
end
|
||||
|
||||
function TestSRMock:test_log_dbg()
|
||||
self.sr.log("dbg", "Hi dude!")
|
||||
assertError(self.sr.log, "debug", "Hi dude!")
|
||||
end
|
||||
|
||||
function TestSRMock:test_xavp()
|
||||
assertNotNil(self.sr.xavp)
|
||||
end
|
||||
|
||||
function TestSRMock:test_xavp_get()
|
||||
assertErrorMsgContains(
|
||||
"dummy not found", self.sr.xavp.get, "dummy", 0, 0)
|
||||
end
|
@ -1,87 +0,0 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
--
|
||||
|
||||
require('luaunit')
|
||||
local pvMock = require 'mocks.pv'
|
||||
local xavpMock = require 'mocks.xavp'
|
||||
|
||||
-- luacheck: ignore TestXAVPMock
|
||||
TestXAVPMock = {}
|
||||
function TestXAVPMock:setUp()
|
||||
self.pv = pvMock.new()
|
||||
self.xavp = xavpMock.new(self.pv)
|
||||
|
||||
self.pv.sets("$xavp(test=>uno)", "uno")
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>uno)"), "uno")
|
||||
self.pv.seti("$xavp(test[0]=>dos)", 4)
|
||||
self.pv.seti("$xavp(test[0]=>dos)", 2)
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>dos)"), 2)
|
||||
self.pv.seti("$xavp(test=>uno)", 3)
|
||||
self.pv.seti("$xavp(test[0]=>uno)", 1)
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>uno)"), 1)
|
||||
self.pv.sets("$xavp(test[0]=>dos)", "dos")
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>dos)"), "dos")
|
||||
self.pv.seti("$xavp(test[0]=>tres)", 3)
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>tres)"), 3)
|
||||
--
|
||||
assertEquals(self.pv.get("$xavp(test[1]=>uno)"), "uno")
|
||||
assertEquals(self.pv.get("$xavp(test[1]=>dos)"), 2)
|
||||
end
|
||||
|
||||
function TestXAVPMock:tearDown()
|
||||
self.pv.vars = {}
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_keys()
|
||||
local l = self.xavp.get_keys("test", 0)
|
||||
assertEvalToTrue(l)
|
||||
assertItemsEquals(l, {"uno", "dos", "tres"})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_keys_1()
|
||||
local l = self.xavp.get_keys("test", 1)
|
||||
assertEvalToTrue(l)
|
||||
assertItemsEquals(l, {"uno", "dos"})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_simple()
|
||||
local l = self.xavp.get("test", 0, 1)
|
||||
assertEvalToTrue(l)
|
||||
assertItemsEquals(l, {uno=1, dos="dos", tres=3})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_simple_1()
|
||||
local l = self.xavp.get("test", 1, 1)
|
||||
assertEvalToTrue(l)
|
||||
assertItemsEquals(l, {uno="uno", dos=2})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get()
|
||||
local l = self.xavp.get("test", 0, 0)
|
||||
assertEvalToTrue(l)
|
||||
assertItemsEquals(l, {uno={1,3}, dos={"dos"}, tres={3}})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_1()
|
||||
local l = self.xavp.get("test", 1, 0)
|
||||
assertEvalToTrue(l)
|
||||
assertItemsEquals(l, {uno={"uno"}, dos={2,4}})
|
||||
end
|
||||
--EOF
|
Loading…
Reference in new issue