From eb64bac459323117431390e7d9c2ac3008797eb0 Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Tue, 8 Aug 2023 19:55:11 -0300 Subject: [PATCH 1/5] sharedstaterpcd --- .../files/usr/libexec/rpcd/shared-state | 54 +++++++++ .../tests/test_rpcd_shared-state.lua | 110 ++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100755 packages/shared-state/files/usr/libexec/rpcd/shared-state create mode 100644 packages/shared-state/tests/test_rpcd_shared-state.lua diff --git a/packages/shared-state/files/usr/libexec/rpcd/shared-state b/packages/shared-state/files/usr/libexec/rpcd/shared-state new file mode 100755 index 000000000..73878bacd --- /dev/null +++ b/packages/shared-state/files/usr/libexec/rpcd/shared-state @@ -0,0 +1,54 @@ +#!/usr/bin/env lua +--[[ +//TODO +]]-- + +local ubus = require "ubus" +local utils = require('lime.utils') +local shared_state = require("shared-state") +local json = require 'luci.jsonc' + +require("nixio.util") + +local function get_from_sharedState (msg) + local sharedState = shared_state.SharedState:new(msg.data_type, nixio.syslog) + local resultTable = sharedState:get() + utils.printJson(resultTable) +end + +local function get_from_sharedState_muti_writer (msg) + local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, nixio.syslog) + local resultTable = sharedState:get() + utils.printJson(resultTable) +end + +local function set_to_sharedState_muti_writer(msg) + local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, nixio.syslog) + local inputTable = json.parse(msg.json) or {} + sharedState:insert(inputTable) +end + + +local methods = { + get_from_sharedState = { data_type = 'value' }, + get_from_sharedState_muti_writer = { data_type = 'value' }, + set_to_sharedState_muti_writer = { data_type = 'value', json = 'value' } +} + +if arg[1] == 'list' then + utils.printJson(methods) +end + +if arg[1] == 'call' then + local msg = utils.rpcd_readline() + msg = json.parse(msg) + if arg[2] == 'get_from_sharedState' then + get_from_sharedState(msg) + elseif arg[2] == 'get_from_sharedState_muti_writer' then + get_from_sharedState_muti_writer(msg) + elseif arg[2] == 'set_to_sharedState_muti_writer' then + set_to_sharedState_muti_writer(msg) + else + utils.printJson({ error = "Method not found" }) + end +end \ No newline at end of file diff --git a/packages/shared-state/tests/test_rpcd_shared-state.lua b/packages/shared-state/tests/test_rpcd_shared-state.lua new file mode 100644 index 000000000..12f9362c5 --- /dev/null +++ b/packages/shared-state/tests/test_rpcd_shared-state.lua @@ -0,0 +1,110 @@ +local utils = require "lime.utils" +local test_utils = require "tests.utils" +local system = require 'lime.system' +local json = require "luci.jsonc" +local shared_state = require("shared-state") + + +local test_file_name = "packages/shared-state/files/usr/libexec/rpcd/shared-state" +local shared_state_rpc = test_utils.load_lua_file_as_function(test_file_name) + +local rpcd_call = test_utils.rpcd_call +local uci + +describe('ubus-shared-state tests #ubus-shared-state', function() + before_each('', function() + test_dir = test_utils.setup_test_dir() + shared_state.DATA_DIR = test_dir + shared_state.PERSISTENT_DATA_DIR = test_dir + end) + + after_each('', function() + test_utils.teardown_test_dir() + end) + + it('test list methods', function() + local response = rpcd_call(shared_state_rpc, {'list'}) + utils.log("ubus-shared-state list") + utils.log(json.stringify(response)) + utils.log("\n") + + assert.is.equal("value", response.get_from_sharedState.data_type) + assert.is.equal("value", response.get_from_sharedState_muti_writer.data_type) + assert.is.equal("value", response.set_to_sharedState_muti_writer.data_type) + assert.is.equal("value", response.set_to_sharedState_muti_writer.json) + + end) + + it('test get data ', function() + local sharedStateA = shared_state.SharedState:new('A') + sharedStateA:insert({ bar = 'foo', baz = 'qux', zig = 'zag'}) + local dbA = sharedStateA:get() + assert.is.equal(dbA.bar.data, 'foo') + assert.is.equal(dbA.baz.data, 'qux') + assert.is.equal(dbA.zig.data, 'zag') + + local response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState'},'{"data_type": "A"}') + assert.is.equal(response.bar.data, 'foo') + assert.is.equal(response.baz.data, 'qux') + assert.is.equal(response.zig.data, 'zag') + end) + + + it('test get multiwriter data ', function() + local sharedStateA = shared_state.SharedStateMultiWriter:new('A') + sharedStateA:insert({ bar = 'foo', baz = 'qux', zig = 'zag'}) + local dbA = sharedStateA:get() + assert.is.equal('foo', dbA.bar.data) + assert.is.equal('zag', dbA.zig.data) + + local response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "A"}') + assert.is.equal(response.bar.data, 'foo') + assert.is.equal(response.baz.data, 'qux') + assert.is.equal(response.zig.data, 'zag') + end) + + it('test set multiwriter data ', function() + local sharedStateA = shared_state.SharedStateMultiWriter:new('A') + sharedStateA:insert({ bar = 'foo', baz = 'qux', zig = 'zag'}) + local dbA = sharedStateA:get() + assert.is.equal('foo', dbA.bar.data) + assert.is.equal('zag', dbA.zig.data) + + local response = rpcd_call(shared_state_rpc,{'call','set_to_sharedState_muti_writer'},'{"data_type": "A", "json": [{zig: "zag"}]"}') + local dbA = sharedStateA:get() + assert.is.equal('foo', dbA.bar.data) + assert.is.equal('newzag', dbA.zig.data) + end) + + +--[['{"password": "foo"}') + it('test get with no config', function() + uci:set("location", "settings", "location") + local response = rpcd_call(ubus_lime_loc, {'call', 'get'}, '') + assert.is.equal("ok", response.status) + assert.is.equal("FIXME", response.location.lat) + assert.is.equal("FIXME", response.location.lon) + assert.is.equal(true, response.default) + end) + + it('test get with no specific location provided defaulting to community', function() + uci:set("location", "settings", "location") + lat = uci:set("location", "settings", "community_latitude", "23.123") + lon = uci:set("location", "settings", "community_longitude", "-45") + + local response = rpcd_call(ubus_lime_loc, {'call', 'get'}, '') + assert.is.equal("ok", response.status) + assert.is.equal("23.123", response.location.lat) + assert.is.equal("-45", response.location.lon) + assert.is.equal(true, response.default) + end) + + before_each('', function() + uci = test_utils.setup_test_uci() + end) + + after_each('', function() + test_utils.teardown_test_uci(uci) + end) + ]]-- +end) From 83a705e1d1fb4a4e382344f68687a7e0a65e49ea Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Thu, 10 Aug 2023 11:37:03 -0300 Subject: [PATCH 2/5] added insert into s_s_multi_writer method --- .../files/usr/libexec/rpcd/shared-state | 23 +++++---- .../tests/test_rpcd_shared-state.lua | 48 ++----------------- 2 files changed, 19 insertions(+), 52 deletions(-) diff --git a/packages/shared-state/files/usr/libexec/rpcd/shared-state b/packages/shared-state/files/usr/libexec/rpcd/shared-state index 73878bacd..0bdce4855 100755 --- a/packages/shared-state/files/usr/libexec/rpcd/shared-state +++ b/packages/shared-state/files/usr/libexec/rpcd/shared-state @@ -1,8 +1,14 @@ -#!/usr/bin/env lua +#!/usr/bin/env lua --[[ -//TODO +Shared State + +Copyright (c) 2023 Javier Jorge +Copyright (c) 2023 Instituto Nacional de Tecnología Industrial +Copyright (C) 2023 Asociación Civil Altermundi + +This is free software, licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 ]]-- - + local ubus = require "ubus" local utils = require('lime.utils') local shared_state = require("shared-state") @@ -22,17 +28,16 @@ local function get_from_sharedState_muti_writer (msg) utils.printJson(resultTable) end -local function set_to_sharedState_muti_writer(msg) +local function insert_into_sharedState_muti_writer(msg) local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, nixio.syslog) - local inputTable = json.parse(msg.json) or {} + local inputTable = msg.json or {} sharedState:insert(inputTable) end - local methods = { get_from_sharedState = { data_type = 'value' }, get_from_sharedState_muti_writer = { data_type = 'value' }, - set_to_sharedState_muti_writer = { data_type = 'value', json = 'value' } + insert_into_sharedState_muti_writer = { data_type = 'value', json = 'value' } } if arg[1] == 'list' then @@ -46,8 +51,8 @@ if arg[1] == 'call' then get_from_sharedState(msg) elseif arg[2] == 'get_from_sharedState_muti_writer' then get_from_sharedState_muti_writer(msg) - elseif arg[2] == 'set_to_sharedState_muti_writer' then - set_to_sharedState_muti_writer(msg) + elseif arg[2] == 'insert_into_sharedState_muti_writer' then + insert_into_sharedState_muti_writer(msg) else utils.printJson({ error = "Method not found" }) end diff --git a/packages/shared-state/tests/test_rpcd_shared-state.lua b/packages/shared-state/tests/test_rpcd_shared-state.lua index 12f9362c5..c940b048c 100644 --- a/packages/shared-state/tests/test_rpcd_shared-state.lua +++ b/packages/shared-state/tests/test_rpcd_shared-state.lua @@ -24,26 +24,21 @@ describe('ubus-shared-state tests #ubus-shared-state', function() it('test list methods', function() local response = rpcd_call(shared_state_rpc, {'list'}) - utils.log("ubus-shared-state list") - utils.log(json.stringify(response)) - utils.log("\n") - assert.is.equal("value", response.get_from_sharedState.data_type) assert.is.equal("value", response.get_from_sharedState_muti_writer.data_type) - assert.is.equal("value", response.set_to_sharedState_muti_writer.data_type) - assert.is.equal("value", response.set_to_sharedState_muti_writer.json) + assert.is.equal("value", response.insert_into_sharedState_muti_writer.data_type) + assert.is.equal("value", response.insert_into_sharedState_muti_writer.json) end) it('test get data ', function() - local sharedStateA = shared_state.SharedState:new('A') + local sharedStateA = shared_state.SharedState:new('wifi_links_info') sharedStateA:insert({ bar = 'foo', baz = 'qux', zig = 'zag'}) local dbA = sharedStateA:get() assert.is.equal(dbA.bar.data, 'foo') assert.is.equal(dbA.baz.data, 'qux') assert.is.equal(dbA.zig.data, 'zag') - - local response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState'},'{"data_type": "A"}') + local response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState'},'{"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') @@ -56,7 +51,6 @@ describe('ubus-shared-state tests #ubus-shared-state', function() local dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('zag', dbA.zig.data) - local response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "A"}') assert.is.equal(response.bar.data, 'foo') assert.is.equal(response.baz.data, 'qux') @@ -69,42 +63,10 @@ describe('ubus-shared-state tests #ubus-shared-state', function() local dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('zag', dbA.zig.data) - - local response = rpcd_call(shared_state_rpc,{'call','set_to_sharedState_muti_writer'},'{"data_type": "A", "json": [{zig: "zag"}]"}') + local response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "A", "json": {"zig": "newzag"}}') local dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('newzag', dbA.zig.data) end) - ---[['{"password": "foo"}') - it('test get with no config', function() - uci:set("location", "settings", "location") - local response = rpcd_call(ubus_lime_loc, {'call', 'get'}, '') - assert.is.equal("ok", response.status) - assert.is.equal("FIXME", response.location.lat) - assert.is.equal("FIXME", response.location.lon) - assert.is.equal(true, response.default) - end) - - it('test get with no specific location provided defaulting to community', function() - uci:set("location", "settings", "location") - lat = uci:set("location", "settings", "community_latitude", "23.123") - lon = uci:set("location", "settings", "community_longitude", "-45") - - local response = rpcd_call(ubus_lime_loc, {'call', 'get'}, '') - assert.is.equal("ok", response.status) - assert.is.equal("23.123", response.location.lat) - assert.is.equal("-45", response.location.lon) - assert.is.equal(true, response.default) - end) - - before_each('', function() - uci = test_utils.setup_test_uci() - end) - - after_each('', function() - test_utils.teardown_test_uci(uci) - end) - ]]-- end) From cb94c1037aa155af239c7e0342f9c2e510b963bc Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Thu, 10 Aug 2023 15:01:17 -0300 Subject: [PATCH 3/5] added more tests and fixed input bugs --- .../files/usr/libexec/rpcd/shared-state | 2 +- .../tests/test_rpcd_shared-state.lua | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/shared-state/files/usr/libexec/rpcd/shared-state b/packages/shared-state/files/usr/libexec/rpcd/shared-state index 0bdce4855..e48552de4 100755 --- a/packages/shared-state/files/usr/libexec/rpcd/shared-state +++ b/packages/shared-state/files/usr/libexec/rpcd/shared-state @@ -56,4 +56,4 @@ if arg[1] == 'call' then else utils.printJson({ error = "Method not found" }) end -end \ No newline at end of file +end diff --git a/packages/shared-state/tests/test_rpcd_shared-state.lua b/packages/shared-state/tests/test_rpcd_shared-state.lua index c940b048c..73691e8a7 100644 --- a/packages/shared-state/tests/test_rpcd_shared-state.lua +++ b/packages/shared-state/tests/test_rpcd_shared-state.lua @@ -52,6 +52,9 @@ describe('ubus-shared-state tests #ubus-shared-state', function() assert.is.equal('foo', dbA.bar.data) assert.is.equal('zag', dbA.zig.data) local response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "A"}') + utils.log('\n') + utils.printJson(response) + utils.log('\n') assert.is.equal(response.bar.data, 'foo') assert.is.equal(response.baz.data, 'qux') assert.is.equal(response.zig.data, 'zag') @@ -69,4 +72,31 @@ describe('ubus-shared-state tests #ubus-shared-state', function() assert.is.equal('newzag', dbA.zig.data) end) + + + + it('test set multiwriter big chunk of data ', function() + + local response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "A", "json": {"zig": "zag"}}') + response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "A"}') + assert.is.equal(response.zig.data, 'zag') + + response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks", "json": {"primero":{"bleachTTL":23,"data":[{"tx_rate":135000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-60,-60],"src_mac":"a8:40:41:1d:f9:35","rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-55],"src_mac":"a8:40:41:1d:f9:35","rx_rate":243000,"signal":-53}],"author":"primero"},"LiMe-da4eaa":{"bleachTTL":27,"data":[{"tx_rate":57800,"dst_mac":"A0:F3:C1:46:28:96","chains":[4,-46],"src_mac":"14:cc:20:da:4e:ab","rx_rate":58500,"signal":4},{"tx_rate":300000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-50,-52],"src_mac":"14:cc:20:da:4e:ac","rx_rate":270000,"signal":-48},{"tx_rate":240000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-81,-67],"src_mac":"14:cc:20:da:4e:ac","rx_rate":135000,"signal":-67}],"author":"LiMe-da4eaa"},"LiMe-462895":{"bleachTTL":28,"data":[{"tx_rate":21700,"dst_mac":"14:CC:20:DA:4E:AB","chains":[5,-48],"signal":5,"rx_rate":43300,"src_mac":"a0:f3:c1:46:28:96"},{"tx_rate":270000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-44],"signal":-44,"rx_rate":270000,"src_mac":"a0:f3:c1:46:28:97"},{"tx_rate":243000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000,"src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}') + response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks"}') + assert.is.equal(response.primero.data.bleachTTL,23) + assert.is.equal(response.primero.data.author,"primero") + + response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks", "json": {"primero":{"bleachTTL":27,"data":[{"tx_rate":135000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-60,-60],"src_mac":"a8:40:41:1d:f9:35","rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-55],"src_mac":"a8:40:41:1d:f9:35","rx_rate":243000,"signal":-53}],"author":"primero"},"LiMe-da4eaa":{"bleachTTL":27,"data":[{"tx_rate":57800,"dst_mac":"A0:F3:C1:46:28:96","chains":[4,-46],"src_mac":"14:cc:20:da:4e:ab","rx_rate":58500,"signal":4},{"tx_rate":300000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-50,-52],"src_mac":"14:cc:20:da:4e:ac","rx_rate":270000,"signal":-48},{"tx_rate":240000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-81,-67],"src_mac":"14:cc:20:da:4e:ac","rx_rate":135000,"signal":-67}],"author":"LiMe-da4eaa"},"LiMe-462895":{"bleachTTL":28,"data":[{"tx_rate":21700,"dst_mac":"14:CC:20:DA:4E:AB","chains":[5,-48],"signal":5,"rx_rate":43300,"src_mac":"a0:f3:c1:46:28:96"},{"tx_rate":270000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-44],"signal":-44,"rx_rate":270000,"src_mac":"a0:f3:c1:46:28:97"},{"tx_rate":243000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000,"src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}') + response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks"}') + assert.is.equal(response.primero.data.bleachTTL,27) + assert.is.equal(response.primero.data.author,"primero") + + response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks", "json": {"primero":{"bleachTTL":23,"data":[{"tx_rate":135000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-60,-60],"src_mac":"a8:40:41:1d:f9:35","rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-55],"src_mac":"a8:40:41:1d:f9:35","rx_rate":243000,"signal":-53}],"author":"primero"},"LiMe-da4eaa":{"bleachTTL":27,"data":[{"tx_rate":57800,"dst_mac":"A0:F3:C1:46:28:96","chains":[4,-46],"src_mac":"14:cc:20:da:4e:ab","rx_rate":58500,"signal":4},{"tx_rate":300000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-50,-52],"src_mac":"14:cc:20:da:4e:ac","rx_rate":270000,"signal":-48},{"tx_rate":240000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-81,-67],"src_mac":"14:cc:20:da:4e:ac","rx_rate":135000,"signal":-67}],"author":"LiMe-da4eaa"},"LiMe-462895":{"bleachTTL":28,"data":[{"tx_rate":21700,"dst_mac":"14:CC:20:DA:4E:AB","chains":[5,-48],"signal":5,"rx_rate":43300,"src_mac":"a0:f3:c1:46:28:96"},{"tx_rate":270000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-44],"signal":-44,"rx_rate":270000,"src_mac":"a0:f3:c1:46:28:97"},{"tx_rate":243000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000,"src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}') + response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks"}') + assert.is.equal(response.primero.data.bleachTTL,23) + assert.is.equal(response.primero.data.author,"primero") + + end) + + end) From 9cc5abf8b40f56df65f4a7ff9772ef5d27e04273 Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Thu, 10 Aug 2023 15:58:53 -0300 Subject: [PATCH 4/5] fixed formating --- .../files/usr/libexec/rpcd/shared-state | 79 +++++----- .../tests/test_rpcd_shared-state.lua | 138 ++++++++++++------ 2 files changed, 140 insertions(+), 77 deletions(-) diff --git a/packages/shared-state/files/usr/libexec/rpcd/shared-state b/packages/shared-state/files/usr/libexec/rpcd/shared-state index e48552de4..bb1396b49 100755 --- a/packages/shared-state/files/usr/libexec/rpcd/shared-state +++ b/packages/shared-state/files/usr/libexec/rpcd/shared-state @@ -7,53 +7,64 @@ Copyright (c) 2023 Instituto Nacional de Tecnología Industrial Copyright (C) 2023 Asociación Civil Altermundi This is free software, licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 -]]-- - -local ubus = require "ubus" -local utils = require('lime.utils') -local shared_state = require("shared-state") -local json = require 'luci.jsonc' - -require("nixio.util") - -local function get_from_sharedState (msg) - local sharedState = shared_state.SharedState:new(msg.data_type, nixio.syslog) - local resultTable = sharedState:get() - utils.printJson(resultTable) +]] -- +local ubus = require "ubus" +local utils = require('lime.utils') +local shared_state = require("shared-state") +local json = require 'luci.jsonc' + +require("nixio.util") + +local function get_from_sharedState(msg) + local sharedState = shared_state.SharedState:new(msg.data_type, + nixio.syslog) + local resultTable = sharedState:get() + utils.printJson(resultTable) end -local function get_from_sharedState_muti_writer (msg) - local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, nixio.syslog) - local resultTable = sharedState:get() - utils.printJson(resultTable) +local function get_from_sharedState_muti_writer(msg) + local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, + nixio.syslog) + local resultTable = sharedState:get() + utils.printJson(resultTable) end local function insert_into_sharedState_muti_writer(msg) - local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, nixio.syslog) - local inputTable = msg.json or {} - sharedState:insert(inputTable) + local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, + nixio.syslog) + local inputTable = msg.json or {} + sharedState:insert(inputTable) end local methods = { - get_from_sharedState = { data_type = 'value' }, - get_from_sharedState_muti_writer = { data_type = 'value' }, - insert_into_sharedState_muti_writer = { data_type = 'value', json = 'value' } + get_from_sharedState = { + data_type = 'value' + }, + get_from_sharedState_muti_writer = { + data_type = 'value' + }, + insert_into_sharedState_muti_writer = { + data_type = 'value', + json = 'value' + } } if arg[1] == 'list' then - utils.printJson(methods) + utils.printJson(methods) end if arg[1] == 'call' then - local msg = utils.rpcd_readline() + local msg = utils.rpcd_readline() msg = json.parse(msg) - if arg[2] == 'get_from_sharedState' then - get_from_sharedState(msg) - elseif arg[2] == 'get_from_sharedState_muti_writer' then - get_from_sharedState_muti_writer(msg) - elseif arg[2] == 'insert_into_sharedState_muti_writer' then - insert_into_sharedState_muti_writer(msg) - else - utils.printJson({ error = "Method not found" }) - end + if arg[2] == 'get_from_sharedState' then + get_from_sharedState(msg) + elseif arg[2] == 'get_from_sharedState_muti_writer' then + get_from_sharedState_muti_writer(msg) + elseif arg[2] == 'insert_into_sharedState_muti_writer' then + insert_into_sharedState_muti_writer(msg) + else + utils.printJson({ + error = "Method not found" + }) + end end diff --git a/packages/shared-state/tests/test_rpcd_shared-state.lua b/packages/shared-state/tests/test_rpcd_shared-state.lua index 73691e8a7..065fd1025 100644 --- a/packages/shared-state/tests/test_rpcd_shared-state.lua +++ b/packages/shared-state/tests/test_rpcd_shared-state.lua @@ -1,15 +1,9 @@ -local utils = require "lime.utils" local test_utils = require "tests.utils" -local system = require 'lime.system' -local json = require "luci.jsonc" -local shared_state = require("shared-state") - +local shared_state = require("shared-state") local test_file_name = "packages/shared-state/files/usr/libexec/rpcd/shared-state" local shared_state_rpc = test_utils.load_lua_file_as_function(test_file_name) - local rpcd_call = test_utils.rpcd_call -local uci describe('ubus-shared-state tests #ubus-shared-state', function() before_each('', function() @@ -23,80 +17,138 @@ describe('ubus-shared-state tests #ubus-shared-state', function() end) it('test list methods', function() - local response = rpcd_call(shared_state_rpc, {'list'}) + local response = rpcd_call(shared_state_rpc, {'list'}) assert.is.equal("value", response.get_from_sharedState.data_type) assert.is.equal("value", response.get_from_sharedState_muti_writer.data_type) assert.is.equal("value", response.insert_into_sharedState_muti_writer.data_type) assert.is.equal("value", response.insert_into_sharedState_muti_writer.json) - end) it('test get data ', function() local sharedStateA = shared_state.SharedState:new('wifi_links_info') - sharedStateA:insert({ bar = 'foo', baz = 'qux', zig = 'zag'}) + sharedStateA:insert({ + bar = 'foo', + baz = 'qux', + zig = 'zag' + }) local dbA = sharedStateA:get() assert.is.equal(dbA.bar.data, 'foo') assert.is.equal(dbA.baz.data, 'qux') assert.is.equal(dbA.zig.data, 'zag') - local response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState'},'{"data_type": "wifi_links_info"}') + local response = rpcd_call(shared_state_rpc, {'call', 'get_from_sharedState'}, + '{"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') end) - it('test get multiwriter data ', function() local sharedStateA = shared_state.SharedStateMultiWriter:new('A') - sharedStateA:insert({ bar = 'foo', baz = 'qux', zig = 'zag'}) + sharedStateA:insert({ + bar = 'foo', + baz = 'qux', + zig = 'zag' + }) local dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('zag', dbA.zig.data) - local response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "A"}') - utils.log('\n') - utils.printJson(response) - utils.log('\n') + local response = rpcd_call(shared_state_rpc, {'call', + 'get_from_sharedState_muti_writer'}, '{"data_type": "A"}') assert.is.equal(response.bar.data, 'foo') assert.is.equal(response.baz.data, 'qux') assert.is.equal(response.zig.data, 'zag') end) - + it('test set multiwriter data ', function() local sharedStateA = shared_state.SharedStateMultiWriter:new('A') - sharedStateA:insert({ bar = 'foo', baz = 'qux', zig = 'zag'}) + sharedStateA:insert({ + bar = 'foo', + baz = 'qux', + zig = 'zag' + }) local dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('zag', dbA.zig.data) - local response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "A", "json": {"zig": "newzag"}}') + local response = rpcd_call(shared_state_rpc, {'call', + 'insert_into_sharedState_muti_writer'}, + '{"data_type": "A", "json": {"zig": "newzag"}}') local dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('newzag', dbA.zig.data) end) - - - it('test set multiwriter big chunk of data ', function() - - local response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "A", "json": {"zig": "zag"}}') - response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "A"}') + + local wifi_status_jsonsample_27 = [[{"data_type": "ref_state_wifilinks", + "json": {"primero":{"bleachTTL":27, "data":[{"tx_rate":135000,"dst_mac": + "A0:F3:C1:46:28:97","chains":[-60,-60], "src_mac":"a8:40:41:1d:f9:35", + "rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC", + "chains":[-57,-55],"src_mac":"a8:40:41:1d:f9:35","rx_rate":243000, + "signal":-53}],"author":"primero"},"LiMe-da4eaa":{"bleachTTL":27,"data": + [{"tx_rate":57800,"dst_mac":"A0:F3:C1:46:28:96","chains":[4,-46], + "src_mac":"14:cc:20:da:4e:ab","rx_rate":58500,"signal":4},{"tx_rate":300000, + "dst_mac":"A0:F3:C1:46:28:97","chains":[-50,-52],"src_mac":"14:cc:20:da:4e:ac", + "rx_rate":270000,"signal":-48},{"tx_rate":240000,"dst_mac":"A8:40:41:1D:F9:35", + "chains":[-81,-67],"src_mac":"14:cc:20:da:4e:ac","rx_rate":135000, + "signal":-67}],"author":"LiMe-da4eaa"},"LiMe-462895":{"bleachTTL":28,"data": + [{"tx_rate":21700,"dst_mac":"14:CC:20:DA:4E:AB","chains":[5,-48], + "signal":5,"rx_rate":43300,"src_mac":"a0:f3:c1:46:28:96"},{"tx_rate":270000, + "dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-44],"signal":-44, + "rx_rate":270000,"src_mac":"a0:f3:c1:46:28:97"},{"tx_rate":243000, + "dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000, + "src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}]] + local wifi_status_jsonsample_23 =[[{"data_type": "ref_state_wifilinks", + "json": {"primero":{"bleachTTL":23, "data":[{"tx_rate":135000,"dst_mac": + "A0:F3:C1:46:28:97","chains":[-60,-60], "src_mac":"a8:40:41:1d:f9:35", + "rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC", + "chains":[-57,-55],"src_mac":"a8:40:41:1d:f9:35","rx_rate":243000, + "signal":-53}],"author":"primero"},"LiMe-da4eaa":{"bleachTTL":27,"data": + [{"tx_rate":57800,"dst_mac":"A0:F3:C1:46:28:96","chains":[4,-46], + "src_mac":"14:cc:20:da:4e:ab","rx_rate":58500,"signal":4},{"tx_rate":300000, + "dst_mac":"A0:F3:C1:46:28:97","chains":[-50,-52],"src_mac":"14:cc:20:da:4e:ac", + "rx_rate":270000,"signal":-48},{"tx_rate":240000,"dst_mac":"A8:40:41:1D:F9:35", + "chains":[-81,-67],"src_mac":"14:cc:20:da:4e:ac","rx_rate":135000, + "signal":-67}],"author":"LiMe-da4eaa"},"LiMe-462895":{"bleachTTL":28,"data": + [{"tx_rate":21700,"dst_mac":"14:CC:20:DA:4E:AB","chains":[5,-48], + "signal":5,"rx_rate":43300,"src_mac":"a0:f3:c1:46:28:96"},{"tx_rate":270000, + "dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-44],"signal":-44, + "rx_rate":270000,"src_mac":"a0:f3:c1:46:28:97"},{"tx_rate":243000, + "dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000, + "src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}]] + + local response = rpcd_call(shared_state_rpc, {'call', + 'insert_into_sharedState_muti_writer'}, + '{"data_type": "A", "json": {"zig": "zag"}}') + response = rpcd_call(shared_state_rpc, {'call', + 'get_from_sharedState_muti_writer'}, '{"data_type": "A"}') assert.is.equal(response.zig.data, 'zag') - response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks", "json": {"primero":{"bleachTTL":23,"data":[{"tx_rate":135000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-60,-60],"src_mac":"a8:40:41:1d:f9:35","rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-55],"src_mac":"a8:40:41:1d:f9:35","rx_rate":243000,"signal":-53}],"author":"primero"},"LiMe-da4eaa":{"bleachTTL":27,"data":[{"tx_rate":57800,"dst_mac":"A0:F3:C1:46:28:96","chains":[4,-46],"src_mac":"14:cc:20:da:4e:ab","rx_rate":58500,"signal":4},{"tx_rate":300000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-50,-52],"src_mac":"14:cc:20:da:4e:ac","rx_rate":270000,"signal":-48},{"tx_rate":240000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-81,-67],"src_mac":"14:cc:20:da:4e:ac","rx_rate":135000,"signal":-67}],"author":"LiMe-da4eaa"},"LiMe-462895":{"bleachTTL":28,"data":[{"tx_rate":21700,"dst_mac":"14:CC:20:DA:4E:AB","chains":[5,-48],"signal":5,"rx_rate":43300,"src_mac":"a0:f3:c1:46:28:96"},{"tx_rate":270000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-44],"signal":-44,"rx_rate":270000,"src_mac":"a0:f3:c1:46:28:97"},{"tx_rate":243000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000,"src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}') - response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks"}') - assert.is.equal(response.primero.data.bleachTTL,23) - assert.is.equal(response.primero.data.author,"primero") - - response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks", "json": {"primero":{"bleachTTL":27,"data":[{"tx_rate":135000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-60,-60],"src_mac":"a8:40:41:1d:f9:35","rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-55],"src_mac":"a8:40:41:1d:f9:35","rx_rate":243000,"signal":-53}],"author":"primero"},"LiMe-da4eaa":{"bleachTTL":27,"data":[{"tx_rate":57800,"dst_mac":"A0:F3:C1:46:28:96","chains":[4,-46],"src_mac":"14:cc:20:da:4e:ab","rx_rate":58500,"signal":4},{"tx_rate":300000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-50,-52],"src_mac":"14:cc:20:da:4e:ac","rx_rate":270000,"signal":-48},{"tx_rate":240000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-81,-67],"src_mac":"14:cc:20:da:4e:ac","rx_rate":135000,"signal":-67}],"author":"LiMe-da4eaa"},"LiMe-462895":{"bleachTTL":28,"data":[{"tx_rate":21700,"dst_mac":"14:CC:20:DA:4E:AB","chains":[5,-48],"signal":5,"rx_rate":43300,"src_mac":"a0:f3:c1:46:28:96"},{"tx_rate":270000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-44],"signal":-44,"rx_rate":270000,"src_mac":"a0:f3:c1:46:28:97"},{"tx_rate":243000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000,"src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}') - response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks"}') - assert.is.equal(response.primero.data.bleachTTL,27) - assert.is.equal(response.primero.data.author,"primero") - - response = rpcd_call(shared_state_rpc,{'call','insert_into_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks", "json": {"primero":{"bleachTTL":23,"data":[{"tx_rate":135000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-60,-60],"src_mac":"a8:40:41:1d:f9:35","rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-55],"src_mac":"a8:40:41:1d:f9:35","rx_rate":243000,"signal":-53}],"author":"primero"},"LiMe-da4eaa":{"bleachTTL":27,"data":[{"tx_rate":57800,"dst_mac":"A0:F3:C1:46:28:96","chains":[4,-46],"src_mac":"14:cc:20:da:4e:ab","rx_rate":58500,"signal":4},{"tx_rate":300000,"dst_mac":"A0:F3:C1:46:28:97","chains":[-50,-52],"src_mac":"14:cc:20:da:4e:ac","rx_rate":270000,"signal":-48},{"tx_rate":240000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-81,-67],"src_mac":"14:cc:20:da:4e:ac","rx_rate":135000,"signal":-67}],"author":"LiMe-da4eaa"},"LiMe-462895":{"bleachTTL":28,"data":[{"tx_rate":21700,"dst_mac":"14:CC:20:DA:4E:AB","chains":[5,-48],"signal":5,"rx_rate":43300,"src_mac":"a0:f3:c1:46:28:96"},{"tx_rate":270000,"dst_mac":"14:CC:20:DA:4E:AC","chains":[-57,-44],"signal":-44,"rx_rate":270000,"src_mac":"a0:f3:c1:46:28:97"},{"tx_rate":243000,"dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000,"src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}') - response = rpcd_call(shared_state_rpc,{'call','get_from_sharedState_muti_writer'},'{"data_type": "ref_state_wifilinks"}') - assert.is.equal(response.primero.data.bleachTTL,23) - assert.is.equal(response.primero.data.author,"primero") - + response = rpcd_call(shared_state_rpc, {'call', + 'insert_into_sharedState_muti_writer'}, + wifi_status_jsonsample_23) + response = rpcd_call(shared_state_rpc, {'call', + 'get_from_sharedState_muti_writer'}, + '{"data_type": "ref_state_wifilinks"}') + assert.is.equal(response.primero.data.bleachTTL, 23) + assert.is.equal(response.primero.data.author, "primero") + + response = rpcd_call(shared_state_rpc, {'call', + 'insert_into_sharedState_muti_writer'},wifi_status_jsonsample_27) + + response = rpcd_call(shared_state_rpc, {'call', + 'get_from_sharedState_muti_writer'}, + '{"data_type": "ref_state_wifilinks"}') + + assert.is.equal(response.primero.data.bleachTTL, 27) + assert.is.equal(response.primero.data.author, "primero") + + response = rpcd_call(shared_state_rpc, {'call', + 'insert_into_sharedState_muti_writer'}, + wifi_status_jsonsample_23) + response = rpcd_call(shared_state_rpc, {'call', + 'get_from_sharedState_muti_writer'}, + '{"data_type": "ref_state_wifilinks"}') + assert.is.equal(response.primero.data.bleachTTL, 23) + assert.is.equal(response.primero.data.author, "primero") end) - - end) From 83dac9668fd769488f3e6a1b2cabe051bf5debad Mon Sep 17 00:00:00 2001 From: Javier Jorge Date: Wed, 16 Aug 2023 15:19:55 -0300 Subject: [PATCH 5/5] fixed missing "l" typo and adopted camel case --- .../files/usr/libexec/rpcd/shared-state | 24 +++--- .../tests/test_rpcd_shared-state.lua | 84 +++++++++---------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/packages/shared-state/files/usr/libexec/rpcd/shared-state b/packages/shared-state/files/usr/libexec/rpcd/shared-state index bb1396b49..7f6e6fda9 100755 --- a/packages/shared-state/files/usr/libexec/rpcd/shared-state +++ b/packages/shared-state/files/usr/libexec/rpcd/shared-state @@ -15,21 +15,21 @@ local json = require 'luci.jsonc' require("nixio.util") -local function get_from_sharedState(msg) +local function getFromSharedState(msg) local sharedState = shared_state.SharedState:new(msg.data_type, nixio.syslog) local resultTable = sharedState:get() utils.printJson(resultTable) end -local function get_from_sharedState_muti_writer(msg) +local function getFromSharedStateMultiWriter(msg) local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, nixio.syslog) local resultTable = sharedState:get() utils.printJson(resultTable) end -local function insert_into_sharedState_muti_writer(msg) +local function insertIntoSharedStateMultiWriter(msg) local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, nixio.syslog) local inputTable = msg.json or {} @@ -37,13 +37,13 @@ local function insert_into_sharedState_muti_writer(msg) end local methods = { - get_from_sharedState = { + getFromSharedState = { data_type = 'value' }, - get_from_sharedState_muti_writer = { + getFromSharedStateMultiWriter = { data_type = 'value' }, - insert_into_sharedState_muti_writer = { + insertIntoSharedStateMultiWriter = { data_type = 'value', json = 'value' } @@ -56,12 +56,12 @@ end if arg[1] == 'call' then local msg = utils.rpcd_readline() msg = json.parse(msg) - if arg[2] == 'get_from_sharedState' then - get_from_sharedState(msg) - elseif arg[2] == 'get_from_sharedState_muti_writer' then - get_from_sharedState_muti_writer(msg) - elseif arg[2] == 'insert_into_sharedState_muti_writer' then - insert_into_sharedState_muti_writer(msg) + if arg[2] == 'getFromSharedState' then + getFromSharedState(msg) + elseif arg[2] == 'getFromSharedStateMultiWriter' then + getFromSharedStateMultiWriter(msg) + elseif arg[2] == 'insertIntoSharedStateMultiWriter' then + insertIntoSharedStateMultiWriter(msg) else utils.printJson({ error = "Method not found" diff --git a/packages/shared-state/tests/test_rpcd_shared-state.lua b/packages/shared-state/tests/test_rpcd_shared-state.lua index 065fd1025..a6ee604a8 100644 --- a/packages/shared-state/tests/test_rpcd_shared-state.lua +++ b/packages/shared-state/tests/test_rpcd_shared-state.lua @@ -1,31 +1,31 @@ -local test_utils = require "tests.utils" -local shared_state = require("shared-state") +local testUtils = require "tests.utils" +local sharedState = require("shared-state") -local test_file_name = "packages/shared-state/files/usr/libexec/rpcd/shared-state" -local shared_state_rpc = test_utils.load_lua_file_as_function(test_file_name) -local rpcd_call = test_utils.rpcd_call +local testFileName = "packages/shared-state/files/usr/libexec/rpcd/shared-state" +local sharedStateRpc = testUtils.load_lua_file_as_function(testFileName) +local rpcdCall = testUtils.rpcd_call describe('ubus-shared-state tests #ubus-shared-state', function() before_each('', function() - test_dir = test_utils.setup_test_dir() - shared_state.DATA_DIR = test_dir - shared_state.PERSISTENT_DATA_DIR = test_dir + testDir = testUtils.setup_test_dir() + sharedState.DATA_DIR = testDir + sharedState.PERSISTENT_DATA_DIR = testDir end) after_each('', function() - test_utils.teardown_test_dir() + testUtils.teardown_test_dir() end) it('test list methods', function() - local response = rpcd_call(shared_state_rpc, {'list'}) - assert.is.equal("value", response.get_from_sharedState.data_type) - assert.is.equal("value", response.get_from_sharedState_muti_writer.data_type) - assert.is.equal("value", response.insert_into_sharedState_muti_writer.data_type) - assert.is.equal("value", response.insert_into_sharedState_muti_writer.json) + local response = rpcdCall(sharedStateRpc, {'list'}) + assert.is.equal("value", response.getFromSharedState.data_type) + assert.is.equal("value", response.getFromSharedStateMultiWriter.data_type) + assert.is.equal("value", response.insertIntoSharedStateMultiWriter.data_type) + assert.is.equal("value", response.insertIntoSharedStateMultiWriter.json) end) it('test get data ', function() - local sharedStateA = shared_state.SharedState:new('wifi_links_info') + local sharedStateA = sharedState.SharedState:new('wifi_links_info') sharedStateA:insert({ bar = 'foo', baz = 'qux', @@ -35,7 +35,7 @@ describe('ubus-shared-state tests #ubus-shared-state', function() assert.is.equal(dbA.bar.data, 'foo') assert.is.equal(dbA.baz.data, 'qux') assert.is.equal(dbA.zig.data, 'zag') - local response = rpcd_call(shared_state_rpc, {'call', 'get_from_sharedState'}, + 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') @@ -43,7 +43,7 @@ describe('ubus-shared-state tests #ubus-shared-state', function() end) it('test get multiwriter data ', function() - local sharedStateA = shared_state.SharedStateMultiWriter:new('A') + local sharedStateA = sharedState.SharedStateMultiWriter:new('A') sharedStateA:insert({ bar = 'foo', baz = 'qux', @@ -52,15 +52,15 @@ describe('ubus-shared-state tests #ubus-shared-state', function() local dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('zag', dbA.zig.data) - local response = rpcd_call(shared_state_rpc, {'call', - 'get_from_sharedState_muti_writer'}, '{"data_type": "A"}') + 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') end) it('test set multiwriter data ', function() - local sharedStateA = shared_state.SharedStateMultiWriter:new('A') + local sharedStateA = sharedState.SharedStateMultiWriter:new('A') sharedStateA:insert({ bar = 'foo', baz = 'qux', @@ -69,8 +69,8 @@ describe('ubus-shared-state tests #ubus-shared-state', function() local dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('zag', dbA.zig.data) - local response = rpcd_call(shared_state_rpc, {'call', - 'insert_into_sharedState_muti_writer'}, + local response = rpcdCall(sharedStateRpc, {'call', + 'insertIntoSharedStateMultiWriter'}, '{"data_type": "A", "json": {"zig": "newzag"}}') local dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) @@ -79,7 +79,7 @@ describe('ubus-shared-state tests #ubus-shared-state', function() it('test set multiwriter big chunk of data ', function() - local wifi_status_jsonsample_27 = [[{"data_type": "ref_state_wifilinks", + local wifiStatusJsonsample27 = [[{"data_type": "ref_state_wifilinks", "json": {"primero":{"bleachTTL":27, "data":[{"tx_rate":135000,"dst_mac": "A0:F3:C1:46:28:97","chains":[-60,-60], "src_mac":"a8:40:41:1d:f9:35", "rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC", @@ -97,7 +97,7 @@ describe('ubus-shared-state tests #ubus-shared-state', function() "rx_rate":270000,"src_mac":"a0:f3:c1:46:28:97"},{"tx_rate":243000, "dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000, "src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}]] - local wifi_status_jsonsample_23 =[[{"data_type": "ref_state_wifilinks", + local wifiStatusJsonsample23 =[[{"data_type": "ref_state_wifilinks", "json": {"primero":{"bleachTTL":23, "data":[{"tx_rate":135000,"dst_mac": "A0:F3:C1:46:28:97","chains":[-60,-60], "src_mac":"a8:40:41:1d:f9:35", "rx_rate":150000,"signal":-57},{"tx_rate":135000,"dst_mac":"14:CC:20:DA:4E:AC", @@ -116,37 +116,37 @@ describe('ubus-shared-state tests #ubus-shared-state', function() "dst_mac":"A8:40:41:1D:F9:35","chains":[-76,-65],"signal":-65,"rx_rate":135000, "src_mac":"a0:f3:c1:46:28:97"}],"author":"LiMe-462895"}}}]] - local response = rpcd_call(shared_state_rpc, {'call', - 'insert_into_sharedState_muti_writer'}, + local response = rpcdCall(sharedStateRpc, {'call', + 'insertIntoSharedStateMultiWriter'}, '{"data_type": "A", "json": {"zig": "zag"}}') - response = rpcd_call(shared_state_rpc, {'call', - 'get_from_sharedState_muti_writer'}, '{"data_type": "A"}') + response = rpcdCall(sharedStateRpc, {'call', + 'getFromSharedStateMultiWriter'}, '{"data_type": "A"}') assert.is.equal(response.zig.data, 'zag') - response = rpcd_call(shared_state_rpc, {'call', - 'insert_into_sharedState_muti_writer'}, - wifi_status_jsonsample_23) - response = rpcd_call(shared_state_rpc, {'call', - 'get_from_sharedState_muti_writer'}, + 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") - response = rpcd_call(shared_state_rpc, {'call', - 'insert_into_sharedState_muti_writer'},wifi_status_jsonsample_27) + response = rpcdCall(sharedStateRpc, {'call', + 'insertIntoSharedStateMultiWriter'},wifiStatusJsonsample27) - response = rpcd_call(shared_state_rpc, {'call', - 'get_from_sharedState_muti_writer'}, + response = rpcdCall(sharedStateRpc, {'call', + 'getFromSharedStateMultiWriter'}, '{"data_type": "ref_state_wifilinks"}') assert.is.equal(response.primero.data.bleachTTL, 27) assert.is.equal(response.primero.data.author, "primero") - response = rpcd_call(shared_state_rpc, {'call', - 'insert_into_sharedState_muti_writer'}, - wifi_status_jsonsample_23) - response = rpcd_call(shared_state_rpc, {'call', - 'get_from_sharedState_muti_writer'}, + 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")