Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed extra info from shared state #1041

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/shared-state/files/usr/libexec/rpcd/shared-state
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 37 additions & 15 deletions packages/shared-state/tests/test_rpcd_shared-state.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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',
Expand All @@ -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)
Expand Down Expand Up @@ -121,16 +143,16 @@ 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'},
wifiStatusJsonsample23)
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)
Expand All @@ -139,16 +161,16 @@ 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'},
wifiStatusJsonsample23)
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)