diff --git a/ngcp/kam_utils.lua b/ngcp/kam_utils.lua deleted file mode 100644 index 4b70b95..0000000 --- a/ngcp/kam_utils.lua +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env lua5.1 --- Kamailio Lua utils -require 'ngcp.utils' - --- kamailio log for a table -function table.log(t, msg, level) - if not level then - level = "dbg" - end - if msg then - sr.log(level, msg) - end - if not t then - -- empty table - return - end - sr.log(level, table.tostring(t)) -end - --- cleans and sets string values from the table list -function sets_avps(list) - if not list then - error("list is empty") - end - - local i, v - - for i,v in pairs(list) do - -- sr.log("dbg","i:" .. i .. " v:" .. v) - sr.pv.unset('$avp(' .. i ..')[*]') - sr.pv.sets('$avp(' .. i .. ')', v) - end -end - --- cleans and sets int values from the table list -function seti_avps(list) - if not list then - error("list is empty") - end - local i, v - - for i,v in pairs(list) do - -- sr.log("debug","i:" .. i .. " v:" .. v) - sr.pv.unset('$avp(' .. i ..')[*]') - sr.pv.seti('$avp(' .. i .. ')', v) - end -end - -function clean_avp(obj) - if not obj then - error("obj is empty") - end - - if type(obj) == "string" then - sr.pv.unset('$avp(' .. obj .. ')[*]') - elseif type(obj) == "table" then - local i,_ - - for i,_ in pairs(obj) do - sr.pv.unset('$avp(' .. i .. ')[*]') - end - end -end - ---EOF \ No newline at end of file diff --git a/tests/kam_utils.lua b/tests/kam_utils.lua deleted file mode 100644 index 1d4336c..0000000 --- a/tests/kam_utils.lua +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env lua5.1 -require('luaunit') -require 'mocks.sr' -require 'ngcp.kam_utils' - -sr = srMock:new() - -TestKamUtils = {} --class - - function TestKamUtils:setUp() - self.list_idsi = { - id1 = 1, - id2 = 2, - id3 = 3 - } - self.list_idss = { - id1 = "1", - id2 = "2", - id3 = "3" - } - end - - function TestKamUtils:test_table_log() - table.log(self.list_idsi, "list ids") - table.log(self.list_idsi, "list ids", "info") - table.log(nil, "list ids") - table.log(self.list_idss, "list ids", nil) - table.log(self.list_idss, nil) - end - - function TestKamUtils:test_sets_avps() - assertError(sets_avps, nil) - sets_avps(self.list_idss) - end - - function TestKamUtils:test_seti_avps() - assertError(seti_avps, nil) - seti_avps(self.list_idsi) - end - - function TestKamUtils:test_clean_avp() - assertError(clean_avp, nil) - clean_avp(self.list_idsi) - clean_avp("testid") - end --- class TestKamUtils - ----- Control test output: -lu = LuaUnit -lu:setOutputType( "TAP" ) -lu:setVerbosity( 1 ) -lu:run() ---EOF \ No newline at end of file