From 7c36dbd97a377629234ef3a695b0bea033cd64bc Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Tue, 22 Aug 2023 14:59:14 -0300 Subject: [PATCH] removed extra info from shared state Removed ttl, author and other information --- .../files/usr/libexec/rpcd/shared-state | 12 ++++- .../tests/test_rpcd_shared-state.lua | 52 +++++++++++++------ 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/packages/shared-state/files/usr/libexec/rpcd/shared-state b/packages/shared-state/files/usr/libexec/rpcd/shared-state index 7f6e6fda9..4fb387a6b 100755 --- a/packages/shared-state/files/usr/libexec/rpcd/shared-state +++ b/packages/shared-state/files/usr/libexec/rpcd/shared-state @@ -19,14 +19,22 @@ local function getFromSharedState(msg) local sharedState = shared_state.SharedState:new(msg.data_type, nixio.syslog) local resultTable = sharedState:get() - utils.printJson(resultTable) + local response ={} + for k,v in pairs(resultTable) do + response[k]=v.data + end + utils.printJson(response) end local function getFromSharedStateMultiWriter(msg) local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, nixio.syslog) local resultTable = sharedState:get() - utils.printJson(resultTable) + local response ={} + for k,v in pairs(resultTable) do + response[k]=v.data + end + utils.printJson(response) end local function insertIntoSharedStateMultiWriter(msg) diff --git a/packages/shared-state/tests/test_rpcd_shared-state.lua b/packages/shared-state/tests/test_rpcd_shared-state.lua index a6ee604a8..e118126b1 100644 --- a/packages/shared-state/tests/test_rpcd_shared-state.lua +++ b/packages/shared-state/tests/test_rpcd_shared-state.lua @@ -1,5 +1,6 @@ local testUtils = require "tests.utils" local sharedState = require("shared-state") +local json = require("luci.jsonc") local testFileName = "packages/shared-state/files/usr/libexec/rpcd/shared-state" local sharedStateRpc = testUtils.load_lua_file_as_function(testFileName) @@ -37,9 +38,9 @@ describe('ubus-shared-state tests #ubus-shared-state', function() assert.is.equal(dbA.zig.data, 'zag') local response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedState'}, '{"data_type": "wifi_links_info"}') - assert.is.equal(response.bar.data, 'foo') - assert.is.equal(response.baz.data, 'qux') - assert.is.equal(response.zig.data, 'zag') + assert.is.equal(response.bar, 'foo') + assert.is.equal(response.baz, 'qux') + assert.is.equal(response.zig, 'zag') end) it('test get multiwriter data ', function() @@ -54,12 +55,12 @@ describe('ubus-shared-state tests #ubus-shared-state', function() assert.is.equal('zag', dbA.zig.data) local response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedStateMultiWriter'}, '{"data_type": "A"}') - assert.is.equal(response.bar.data, 'foo') - assert.is.equal(response.baz.data, 'qux') - assert.is.equal(response.zig.data, 'zag') + assert.is.equal(response.bar, 'foo') + assert.is.equal(response.baz, 'qux') + assert.is.equal(response.zig, 'zag') end) - it('test set multiwriter data ', function() + it('test insert multiwriter data ', function() local sharedStateA = sharedState.SharedStateMultiWriter:new('A') sharedStateA:insert({ bar = 'foo', @@ -72,7 +73,28 @@ describe('ubus-shared-state tests #ubus-shared-state', function() local response = rpcdCall(sharedStateRpc, {'call', 'insertIntoSharedStateMultiWriter'}, '{"data_type": "A", "json": {"zig": "newzag"}}') - local dbA = sharedStateA:get() + dbA = sharedStateA:get() + assert.is.equal('foo', dbA.bar.data) + assert.is.equal('newzag', dbA.zig.data) + end) + + it('test insert multiwriter data ', function() + local sharedStateA = sharedState.SharedStateMultiWriter:new('A') + sharedStateA:insert({ + bar = 'foo', + baz = 'qux', + zig = 'zag' + }) + local response = rpcdCall(sharedStateRpc, {'call', + 'getFromSharedStateMultiWriter'}, '{"data_type": "A"}') + assert.is.equal('foo', response.bar) + assert.is.equal('zag', response.zig) + response.zig="newzag" + callargs = '{"data_type": "A", "json": '..json.stringify(response)..'}' + local response = rpcdCall(sharedStateRpc, {'call', + 'insertIntoSharedStateMultiWriter'}, + callargs) + dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('newzag', dbA.zig.data) end) @@ -121,7 +143,7 @@ describe('ubus-shared-state tests #ubus-shared-state', function() '{"data_type": "A", "json": {"zig": "zag"}}') response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedStateMultiWriter'}, '{"data_type": "A"}') - assert.is.equal(response.zig.data, 'zag') + assert.is.equal(response.zig, 'zag') response = rpcdCall(sharedStateRpc, {'call', 'insertIntoSharedStateMultiWriter'}, @@ -129,8 +151,8 @@ describe('ubus-shared-state tests #ubus-shared-state', function() response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedStateMultiWriter'}, '{"data_type": "ref_state_wifilinks"}') - assert.is.equal(response.primero.data.bleachTTL, 23) - assert.is.equal(response.primero.data.author, "primero") + assert.is.equal(response.primero.bleachTTL, 23) + assert.is.equal(response.primero.author, "primero") response = rpcdCall(sharedStateRpc, {'call', 'insertIntoSharedStateMultiWriter'},wifiStatusJsonsample27) @@ -139,8 +161,8 @@ describe('ubus-shared-state tests #ubus-shared-state', function() 'getFromSharedStateMultiWriter'}, '{"data_type": "ref_state_wifilinks"}') - assert.is.equal(response.primero.data.bleachTTL, 27) - assert.is.equal(response.primero.data.author, "primero") + assert.is.equal(response.primero.bleachTTL, 27) + assert.is.equal(response.primero.author, "primero") response = rpcdCall(sharedStateRpc, {'call', 'insertIntoSharedStateMultiWriter'}, @@ -148,7 +170,7 @@ describe('ubus-shared-state tests #ubus-shared-state', function() response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedStateMultiWriter'}, '{"data_type": "ref_state_wifilinks"}') - assert.is.equal(response.primero.data.bleachTTL, 23) - assert.is.equal(response.primero.data.author, "primero") + assert.is.equal(response.primero.bleachTTL, 23) + assert.is.equal(response.primero.author, "primero") end) end)