diff --git a/mocks/sr.lua b/mocks/sr.lua index a64a0d9..1e1571d 100644 --- a/mocks/sr.lua +++ b/mocks/sr.lua @@ -98,6 +98,16 @@ pvMock = { local t = {} t.__class__ = 'pvMock' + -- fake pseudo vars go here + t.vars_pv = { + ro = { + si = "127.0.0.1", + sp = "9090" + }, + rw = { + rU = "noname" + } + } t.vars = {} t.hdr = hdr @@ -169,6 +179,22 @@ pvMock = { end end + function t._is_pv(id) + local k0,k,_ + local real_id = string.match(id, '%$(%w+)$') + if not real_id then + return + end + for k,_ in pairs(t.vars_pv) do + for k0,_ in pairs(t.vars_pv[k]) do + --print(string.format("id:%s, k:%s k0:%s", real_id, k, k0)) + if real_id == k0 then + return { id=k0, clean=false, type='pv', mode=k} + end + end + end + end + function t._is(id) if not id then error("id empty") @@ -184,6 +210,9 @@ pvMock = { if not result then result = t._is_hdr(id) end + if not result then + result = t._is_pv(id) + end if not result then error(string.format("not implemented or wrong id:%s", id)) end @@ -231,6 +260,8 @@ pvMock = { if t.hdr then return t.hdr._get_header(result.id) end + elseif result.type == 'pv' then + return t.vars_pv[result.mode][result.id] end end @@ -252,6 +283,8 @@ pvMock = { elseif result.type == 'avp' then t.vars[result.private_id] = Stack:new() t.vars[result.private_id]:push(value) + elseif result.type == 'pv' and result.mode == 'rw' then + t.vars_pv.rw[result.id] = value end end @@ -275,6 +308,8 @@ pvMock = { end elseif result.type == 'avp' then t.vars[result.private_id]:push(value) + elseif result.type == 'pv' and result.mode == 'rw' then + t.vars_pv.rw[result.id] = value end end diff --git a/tests/mocks.lua b/tests/mocks.lua index f221df9..50e69fe 100644 --- a/tests/mocks.lua +++ b/tests/mocks.lua @@ -71,6 +71,28 @@ TestSRMock = {} assertEquals(self.sr.pv._clean_id('u25'), 'u25') end + function TestSRMock:test_is_pv_simple() + local result + result = self.sr.pv._is_pv("$si") + assertTrue(result) + assertEquals(result.type, 'pv') + assertEquals(result.id, 'si') + assertEquals(result.key, nil) + assertEquals(result.mode, 'ro') + assertFalse(result.clean) + end + + function TestSRMock:test_is_pv_rw() + local result + result = self.sr.pv._is_pv("$rU") + assertTrue(result) + assertEquals(result.type, 'pv') + assertEquals(result.id, 'rU') + assertEquals(result.key, nil) + assertEquals(result.mode, 'rw') + assertFalse(result.clean) + end + function TestSRMock:test_is_hdr_simple() local result result = self.sr.pv._is_hdr("$hdr(id)") @@ -317,6 +339,16 @@ TestSRMock = {} assertEquals(self.sr.pv.get("$hdr(From)"), "hola") end + function TestSRMock:test_pv_seti() + self.sr.pv.seti("$rU", 0) + assertEquals(self.sr.pv.get("$rU"), 0) + end + + function TestSRMock:test_pv_sets() + self.sr.pv.sets("$rU", "0") + assertEquals(self.sr.pv.get("$rU"), "0") + end + function TestSRMock:test_unset_var() self.sr.pv.sets("$var(hithere)", "value") assertEquals(self.sr.pv.get("$var(hithere)"), "value")