TT#78651 migrate to new KEMI pvx interface

Change-Id: I1a5c4cb887276c363ba1158ec72525c70dc17901
changes/39/39339/1
Victor Seva 6 years ago
parent dc1ba69f3f
commit 2b57bbe5bb

@ -1,2 +1,2 @@
globals = {'sr', '_ENV'}
globals = {'KSR', '_ENV'}
ignore = { '212' }

@ -66,6 +66,56 @@ local pvxMock = {
return t._get_xavp(xavp_name, "NULL_PRINT")
end
function t.xavp_get_keys(xavp_name, index)
local private_id = "xavp:" .. xavp_name
local output = {}
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
local xavp = t.pv.vars[private_id][index]
for k,_ in pairs(xavp) do
table.insert(output, k)
end
return output
end
function t.xavp_getd(xavp_name)
local private_id = "xavp:" .. xavp_name
local output = {}
if not t.pv.vars[private_id] then
error(string.format("%s not found", xavp_name))
end
for _,v in ipairs(t.pv.vars[private_id]:list()) do
local avp = {}
for k, s in pairs(v) do
avp[k] = s:list()
end
table.insert(output, avp)
end
return output
end
function t.xavp_getd_p1(xavp_name, index)
local private_id = "xavp:" .. xavp_name
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
local output = {}
for k, s in pairs(t.pv.vars[private_id][index]) do
output[k] = s:list()
end
return output
end
local pvxMock_MT = { __index = pvxMock }
setmetatable(t, pvxMock_MT)
return t

@ -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

@ -77,7 +77,7 @@ NGCPRealPrefs_MT.__tostring = function ()
contract = NGCPContractPrefs:xavp(level),
}
local contract_keys = {}
local values = sr.xavp.get(xavp.contract.name, 0, 0)
local values = KSR.pvx.xavp_getd_p1(xavp.contract.name, 0)
for _,v in pairs(keys) do
local value = values[v]
if value then
@ -92,7 +92,7 @@ NGCPRealPrefs_MT.__tostring = function ()
peer = NGCPPeerPrefs:xavp(level),
}
local peer_keys = {}
local values = sr.xavp.get(xavp.peer.name, 0, 0)
local values = KSR.pvx.xavp_getd_p1(xavp.peer.name, 0)
for _,v in pairs(keys) do
local value = values[v]
if value then
@ -110,9 +110,9 @@ NGCPRealPrefs_MT.__tostring = function ()
usr = NGCPUserPrefs:xavp(level)
}
local real_values = {}
local dom_values = sr.xavp.get(xavp.dom.name, 0, 0)
local prof_values = sr.xavp.get(xavp.prof.name, 0, 0)
local usr_values = sr.xavp.get(xavp.usr.name, 0, 0)
local dom_values = KSR.pvx.xavp_getd_p1(xavp.dom.name, 0)
local prof_values = KSR.pvx.xavp_getd_p1(xavp.prof.name, 0)
local usr_values = KSR.pvx.xavp_getd_p1(xavp.usr.name, 0)
for _,v in pairs(keys) do
local value = usr_values[v]
if not value then

@ -64,7 +64,7 @@ local NGCPXAvp_MT = {
NGCPXAvp_MT.__tostring = function (s)
local output
local ll = sr.xavp.get(s.name, 0)
local ll = KSR.pvx.xavp_getd_p1(s.name, 0)
if ll then
output = utable.tostring(ll)
end
@ -142,7 +142,7 @@ local NGCPXAvp_MT = {
function NGCPXAvp:all(key)
if key then
local t = sr.xavp.get(self.name, 0, 0)
local t = KSR.pvx.xavp_getd_p1(self.name, 0)
if t then
return t[key];
end

@ -1,3 +1,3 @@
globals = {'KSR', 'sr'}
globals = {'KSR'}
-- until we fix the luaunit new format at run_tests.sh
ignore = {'assert.*', '212'}

@ -22,9 +22,9 @@ require('luaunit')
local pvMock = require 'mocks.pv'
local pvxMock = require 'mocks.pvx'
-- luacheck: ignore TestXAVPMock
TestXAVPMock = {}
function TestXAVPMock:setUp()
-- luacheck: ignore TestPVXMock
TestPVXMock = {}
function TestPVXMock:setUp()
self.pv = pvMock.new()
self.pvx = pvxMock.new(self.pv)
@ -45,21 +45,48 @@ TestXAVPMock = {}
assertEquals(self.pv.get("$xavp(test[1]=>dos)"), 2)
end
function TestXAVPMock:tearDown()
function TestPVXMock:tearDown()
self.pv.vars = {}
end
function TestXAVPMock:test_xavp_get()
function TestPVXMock:test_xavp_get()
local l = self.pvx.xavp_get("test")
local m = tostring(self.pv.vars["xavp:test"])
assertItemsEquals(l, "<<xavp:"..m:sub(8)..">>")
end
function TestXAVPMock:test_xavp_gete()
function TestPVXMock:test_xavp_gete()
assertItemsEquals(self.pvx.xavp_gete("fake"), "")
end
function TestXAVPMock:test_xavp_getw()
function TestPVXMock:test_xavp_getw()
assertItemsEquals(self.pvx.xavp_getw("fake"), "<null>")
end
function TestPVXMock:test_get_keys()
local l = self.pvx.xavp_get_keys("test", 0)
assertNotNil(l)
assertItemsEquals(l, {"uno", "dos", "tres"})
end
function TestPVXMock:test_get_keys_1()
local l = self.pvx.xavp_get_keys("test", 1)
assertNotNil(l)
assertItemsEquals(l, {"uno", "dos"})
end
function TestPVXMock:test_getd()
local l = self.pvx.xavp_getd("test")
assertNotNil(l)
assertItemsEquals(l, {
{uno={1,3}, dos={"dos"}, tres={3}},
{uno={"uno"}, dos={2,4}}
})
end
function TestPVXMock:test_getd_p1()
local l = self.pvx.xavp_getd_p1("test", 1)
assertNotNil(l)
assertItemsEquals(l, {uno={"uno"}, dos={2,4}})
end
--EOF

@ -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

@ -29,9 +29,7 @@ local utils = require 'ngcp.utils'
local utable = utils.table
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env
local dp_vars = DPFetch:new()
@ -75,7 +73,7 @@ TestNGCP = {} --class
end
function TestNGCP:test_config()
assertEvalToTrue(self.ngcp.config)
assertNotNil(self.ngcp.config)
assert(self.ngcp.config.env)
assertIsNil(self.ngcp.config.con)
end
@ -98,24 +96,24 @@ TestNGCP = {} --class
function TestNGCP:test_prefs_init()
KSR.log("dbg", "TestNGCP:test_prefs_init")
assertEvalToTrue(self.ngcp)
assertEvalToTrue(self.ngcp.prefs)
assertEvalToTrue(self.ngcp.prefs.peer)
assertNotNil(self.ngcp)
assertNotNil(self.ngcp.prefs)
assertNotNil(self.ngcp.prefs.peer)
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.usr)
assertNotNil(self.ngcp.prefs.usr)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.dom)
assertNotNil(self.ngcp.prefs.dom)
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.real)
assertNotNil(self.ngcp.prefs.real)
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.prof)
assertNotNil(self.ngcp.prefs.prof)
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.fax)
assertNotNil(self.ngcp.prefs.fax)
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
end

@ -22,9 +22,7 @@ local lemock = require('lemock')
local CPFetch = require 'tests_v.cp_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local cp_vars = CPFetch:new()

@ -24,9 +24,7 @@ local lemock = require('lemock')
local DPFetch = require 'tests_v.dp_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local dp_vars = DPFetch:new()

@ -22,9 +22,7 @@ local lemock = require('lemock')
local FPFetch = require 'tests_v.fp_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local fp_vars = FPFetch:new()

@ -25,9 +25,7 @@ local PPFetch = require 'tests_v.pp_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local pp_vars = PPFetch:new()

@ -22,9 +22,7 @@ local lemock = require('lemock')
local PProfFetch = require 'tests_v.pprof_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local pprof_vars = PProfFetch:new()

@ -24,9 +24,7 @@ local NGCPPeerPrefs = require 'ngcp.pp'
local NGCPRealPrefs = require 'ngcp.rp'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
-- luacheck: ignore TestNGCPRealPrefs
TestNGCPRealPrefs = {} --class

@ -24,9 +24,7 @@ local utable = utils.table
local UPFetch = require 'tests_v.up_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local up_vars = UPFetch:new()

@ -21,9 +21,7 @@ require('luaunit')
local NGCPXAvp = require 'ngcp.xavp'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
local vals = {
{

@ -22,9 +22,7 @@ local NGCPXAvp = require 'ngcp.xavp'
local NGCPAvp = require 'ngcp.avp'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
KSR = ksrMock.new()
sr = srMock.new(KSR)
-- luacheck: ignore TestUseCases
TestUseCases = {}

Loading…
Cancel
Save