Added keys field to insert the keys used

squeeze-backports
Victor Seva 13 years ago
parent f4b5526d2c
commit db2d4a6aad

@ -16,14 +16,15 @@ NGCPXAvp_MT = {
end end
local t = { local t = {
group = group group = group,
keys = {}
} }
if level == 'callee' then if level == 'callee' then
t.level = 1 t.level = 1
else else
t.level = 0 t.level = 0
end end
NGCPXAvp._create(t.level,group,l) NGCPXAvp._create(t, t.level,group,l)
NGCPXAvp_MT.__call = function(t, key, value) NGCPXAvp_MT.__call = function(t, key, value)
if not key then if not key then
error("key is empty") error("key is empty")
@ -33,8 +34,10 @@ NGCPXAvp_MT = {
if not value then if not value then
return sr.pv.get(id) return sr.pv.get(id)
elseif type(value) == "number" then elseif type(value) == "number" then
table.add(t.keys, key)
sr.pv.seti(id, value) sr.pv.seti(id, value)
elseif type(value) == "string" then elseif type(value) == "string" then
table.add(t.keys, key)
sr.pv.sets(id, value) sr.pv.sets(id, value)
else else
error("value is not a number or string") error("value is not a number or string")
@ -74,7 +77,7 @@ NGCPXAvp_MT = {
end end
end end
function NGCPXAvp._create(level, group, l) function NGCPXAvp:_create(level, group, l)
local i, name local i, name
-- create dummy vars -- create dummy vars
name = string.format("$xavp(%s=>dummy)", group) name = string.format("$xavp(%s=>dummy)", group)
@ -83,6 +86,7 @@ NGCPXAvp_MT = {
NGCPXAvp._setvalue(name, 0, "caller") -- caller -> [0] NGCPXAvp._setvalue(name, 0, "caller") -- caller -> [0]
for i=1,#l do for i=1,#l do
name = string.format("$xavp(%s[%d]=>%s)", group, level, l[i].attribute) name = string.format("$xavp(%s[%d]=>%s)", group, level, l[i].attribute)
table.add(self.keys, l[i].attribute)
NGCPXAvp._setvalue(name, l[i].type, l[i].value) NGCPXAvp._setvalue(name, l[i].type, l[i].value)
end end
end end

@ -17,20 +17,20 @@ vals = {
}, },
{ {
id = 2, id = 2,
uuid = "94023caf-dfba-4f33-8bdb-b613ce627613", uuid = "ae736f72-21d1-4ea6-a3ea-4d7f56b3887c",
username = "testuser2", username = "testuser1",
domain = "192.168.51.56", domain = "192.168.51.56",
attribute = "account_id", attribute = "whatever",
type = 1, type = 1,
value = 2, value = 2,
last_modified = "1900-01-01 00:00:01" last_modified = "1900-01-01 00:00:01"
}, },
{ {
id = 3, id = 3,
uuid = "94023caf-dfba-4f33-8bdb-b613ce627613", uuid = "ae736f72-21d1-4ea6-a3ea-4d7f56b3887c",
username = "testuser2", username = "testuser1",
domain = "192.168.51.56", domain = "192.168.51.56",
attribute = "account_id", attribute = "elsewhere",
type = 0, type = 0,
value = "2", value = "2",
last_modified = "1900-01-01 00:00:01" last_modified = "1900-01-01 00:00:01"
@ -73,6 +73,15 @@ TestNGCPXAvp = {} --class
assertFalse(self.xavp("testid")) assertFalse(self.xavp("testid"))
assertFalse(sr.pv.get("$xavp(peer[0]=>testid)")) assertFalse(sr.pv.get("$xavp(peer[0]=>testid)"))
end end
function TestNGCPXAvp:test_keys()
assertItemsEquals(self.xavp.keys, {"account_id","whatever","elsewhere"})
self.xavp("testid", 1)
assertItemsEquals(self.xavp.keys, {"account_id","whatever","elsewhere","testid"})
self.xavp:clean()
assertItemsEquals(self.xavp.keys, {"account_id","whatever","elsewhere","testid"})
end
-- class TestNGCPXAvp -- class TestNGCPXAvp
---- Control test output: ---- Control test output:

Loading…
Cancel
Save