diff --git a/packages/shared-state-async/files/usr/libexec/rpcd/shared-state-async b/packages/shared-state-async/files/usr/libexec/rpcd/shared-state-async index 171f0d67b..b5d1a2ac3 100755 --- a/packages/shared-state-async/files/usr/libexec/rpcd/shared-state-async +++ b/packages/shared-state-async/files/usr/libexec/rpcd/shared-state-async @@ -25,13 +25,14 @@ local function parseErrors() elseif string.find(error, "Invalid peer address:") ~= nil then utils.printJson({ error = "invalid_peer_address" - }) + }) end end end local function getFromSharedState(msg) - print(utils.unsafe_shell("shared-state-async get " .. msg.data_type .. " 2> " .. ERROR_LOG_FILE_NAME)) + print(utils.unsafe_shell("shared-state-async get " .. msg.data_type .. + " 2> " .. ERROR_LOG_FILE_NAME)) --if ther are errors the function wont return and wont print. parseErrors() end @@ -39,9 +40,11 @@ end local function sync(msg) if (type(msg.peers_ip) == 'table') then utils.unsafe_shell("shared-state-async sync " .. - msg.data_type .. " " .. table.concat(msg.peers_ip, " ") .. " 2> " .. ERROR_LOG_FILE_NAME) + msg.data_type .. " " .. table.concat(msg.peers_ip, " ") .. " 2> " + .. ERROR_LOG_FILE_NAME) else - utils.unsafe_shell("shared-state-async sync " .. msg.data_type .. " " .. " 2> " .. ERROR_LOG_FILE_NAME) + utils.unsafe_shell("shared-state-async sync " .. msg.data_type .. " " .. + " 2> " .. ERROR_LOG_FILE_NAME) end parseErrors() utils.printJson({ @@ -66,7 +69,7 @@ if arg[1] == 'list' then end if arg[1] == 'call' then - utils.unsafe_shell("rm " .. ERROR_LOG_FILE_NAME .."> /dev/null 2>&1") + utils.unsafe_shell("rm " .. ERROR_LOG_FILE_NAME .. "> /dev/null 2>&1") local msg = utils.rpcd_readline() msg = json.parse(msg) if arg[2] == 'getFromSharedState' then diff --git a/packages/shared-state-async/tests/test_rpcd_shared-state-async.lua b/packages/shared-state-async/tests/test_rpcd_shared-state-async.lua new file mode 100644 index 000000000..4bc0da6f5 --- /dev/null +++ b/packages/shared-state-async/tests/test_rpcd_shared-state-async.lua @@ -0,0 +1,41 @@ +local testUtils = require "tests.utils" +local sharedState = require("shared-state") +local json = require("luci.jsonc") + +local testFileName = "packages/shared-state-async/files/usr/libexec/rpcd/shared-state-async" +local sharedStateRpc = testUtils.load_lua_file_as_function(testFileName) +local rpcdCall = testUtils.rpcd_call + +--sicce there is no Shared State async binary, testing posiblilites are reduced +--manual testing can be done on a routeer with bat-hosts package using this: +-- # ubus -S call shared-state-async getFromSharedState "{'data_type': 'bat-hosts'}" +-- # ubus -S call shared-state-async getFromSharedState "{'data_type': 'bat-hosss'}" +-- {"error":"invalid_data_type"} +-- # ubus -S call shared-state-async sync "{'data_type': 'bat-hosts' ,'peers_ip':['10.0.0.1','10.0.0.2']}'" +-- {"status":"success"} +-- # ubus -S call shared-state-async sync "{'data_type': 'bat-hosts' ,'peers_ip':['10.0.0.1','10.0..2']}'" +-- {"error":"invalid_peer_address"} +-- # ubus -S call shared-state-async sync "{'data_type': 'bat-hoss' ,'peers_ip':['10.0.0.1','10.0.0.2']}'" +-- {"error":"invalid_data_type"} + + + +describe('ubus-shared-state tests #ubus-shared-state', function() + before_each('', function() + testDir = testUtils.setup_test_dir() + sharedState.DATA_DIR = testDir + sharedState.PERSISTENT_DATA_DIR = testDir + end) + + after_each('', function() + testUtils.teardown_test_dir() + end) + + it('test list methods', function() + local response = rpcdCall(sharedStateRpc, {'list'}) + assert.is.equal("value", response.getFromSharedState.data_type) + assert.is.equal("value", response.sync.data_type) + assert.is.equal("value", response.sync.peers_ip) + + end) +end)