From 8f1e6708b57698b5b0a770ee97754501f3c66d83 Mon Sep 17 00:00:00 2001 From: Kapil Bansal Date: Thu, 17 Jun 2021 17:48:18 +0530 Subject: [PATCH] [refactor] Fix inconsistent indentation --- openwrt-openwisp-monitoring/tests/env1.lua | 46 ++++++++-------- .../tests/test_dhcp.lua | 8 +-- .../tests/test_neighbors.lua | 14 ++--- .../tests/test_resources.lua | 12 ++--- .../tests/test_utils.lua | 54 +++++++++---------- 5 files changed, 67 insertions(+), 67 deletions(-) diff --git a/openwrt-openwisp-monitoring/tests/env1.lua b/openwrt-openwisp-monitoring/tests/env1.lua index bd2a9a0..ee9f1f9 100644 --- a/openwrt-openwisp-monitoring/tests/env1.lua +++ b/openwrt-openwisp-monitoring/tests/env1.lua @@ -29,29 +29,29 @@ env.uci = { } env.io = { - popen = function(arg) - if arg == 'df' then - return io.open(test_file_dir .. 'disk_usage.txt') - elseif arg == 'cat /proc/cpuinfo | grep -c processor' then - local f = assert(io.tmpfile()) - f:write('8') - f:seek('set',0) - return f - elseif arg == 'cat /proc/net/arp 2> /dev/null' then - return io.open(test_file_dir .. 'parse_app.txt') - elseif arg == 'ip -json neigh 2> /dev/null' then - return io.open(test_file_dir .. 'ip_json_neigh.txt') - elseif arg == 'ip neigh 2> /dev/null' then - return io.open(test_file_dir .. 'ip_neigh.txt') - end - end, - open = function(arg) - if arg == '/tmp/dhcp.leases' then - return io.open('./test_files/dhcp_leases.txt') - else - return io.open(arg) - end - end + popen = function(arg) + if arg == 'df' then + return io.open(test_file_dir .. 'disk_usage.txt') + elseif arg == 'cat /proc/cpuinfo | grep -c processor' then + local f = assert(io.tmpfile()) + f:write('8') + f:seek('set',0) + return f + elseif arg == 'cat /proc/net/arp 2> /dev/null' then + return io.open(test_file_dir .. 'parse_app.txt') + elseif arg == 'ip -json neigh 2> /dev/null' then + return io.open(test_file_dir .. 'ip_json_neigh.txt') + elseif arg == 'ip neigh 2> /dev/null' then + return io.open(test_file_dir .. 'ip_neigh.txt') + end + end, + open = function(arg) + if arg == '/tmp/dhcp.leases' then + return io.open('./test_files/dhcp_leases.txt') + else + return io.open(arg) + end + end } env.ubus = { diff --git a/openwrt-openwisp-monitoring/tests/test_dhcp.lua b/openwrt-openwisp-monitoring/tests/test_dhcp.lua index ae600e0..fc5daab 100644 --- a/openwrt-openwisp-monitoring/tests/test_dhcp.lua +++ b/openwrt-openwisp-monitoring/tests/test_dhcp.lua @@ -6,9 +6,9 @@ local luaunit = require('luaunit') TestDhcp = { setUp = function() - local env = require('env1') - package.loaded.uci = env.uci - package.loaded.io = env.io + local env = require('env1') + package.loaded.uci = env.uci + package.loaded.io = env.io end, tearDown = function() end @@ -18,7 +18,7 @@ TestDhcp = { function TestDhcp.test_dhcp_leases() local dhcp_functions = require('dhcp') - luaunit.assertEquals(dhcp_functions.get_dhcp_leases(), dhcp_data.leases) + luaunit.assertEquals(dhcp_functions.get_dhcp_leases(), dhcp_data.leases) luaunit.assertEquals(dhcp_functions.parse_dhcp_lease_file('/tmp/dhcp.leases',{}), dhcp_data.leases) end diff --git a/openwrt-openwisp-monitoring/tests/test_neighbors.lua b/openwrt-openwisp-monitoring/tests/test_neighbors.lua index 78772bb..2c337d5 100644 --- a/openwrt-openwisp-monitoring/tests/test_neighbors.lua +++ b/openwrt-openwisp-monitoring/tests/test_neighbors.lua @@ -6,23 +6,23 @@ local neighbor_data = require('test_files/neighbors_data') TestNeighbor = { setUp = function() - local env = require('env1') - package.loaded.io = env.io + local env = require('env1') + package.loaded.io = env.io end, tearDown = function() end } function TestNeighbor.testArpTable() - local neighbor = require('neighbors') + local neighbor = require('neighbors') - luaunit.assertEquals(neighbor.parse_arp(), neighbor_data.sample_parse_arp) + luaunit.assertEquals(neighbor.parse_arp(), neighbor_data.sample_parse_arp) - luaunit.assertEquals(neighbor.get_ip_neigh_json(), neighbor_data.sample_ip_neigh) + luaunit.assertEquals(neighbor.get_ip_neigh_json(), neighbor_data.sample_ip_neigh) - luaunit.assertEquals(neighbor.get_ip_neigh(), neighbor_data.sample_ip_neigh) + luaunit.assertEquals(neighbor.get_ip_neigh(), neighbor_data.sample_ip_neigh) - luaunit.assertEquals(neighbor.get_neighbors(), neighbor_data.sample_ip_neigh) + luaunit.assertEquals(neighbor.get_neighbors(), neighbor_data.sample_ip_neigh) end os.exit( luaunit.LuaUnit.run() ) diff --git a/openwrt-openwisp-monitoring/tests/test_resources.lua b/openwrt-openwisp-monitoring/tests/test_resources.lua index 925421e..2d78867 100644 --- a/openwrt-openwisp-monitoring/tests/test_resources.lua +++ b/openwrt-openwisp-monitoring/tests/test_resources.lua @@ -6,23 +6,23 @@ local resources_data = require('test_files/resources_data') TestResources = { setUp = function() - local env = require('env1') - package.loaded.io = env.io + local env = require('env1') + package.loaded.io = env.io end, tearDown = function() end } function TestResources.test_disk_usage() - local resources = require('resources') + local resources = require('resources') - luaunit.assertEquals(resources.parse_disk_usage(), resources_data.disk_usage) + luaunit.assertEquals(resources.parse_disk_usage(), resources_data.disk_usage) end function TestResources.test_get_cpus() - local resources = require('resources') + local resources = require('resources') - luaunit.assertEquals(resources.get_cpus(), 8) + luaunit.assertEquals(resources.get_cpus(), 8) end os.exit( luaunit.LuaUnit.run() ) diff --git a/openwrt-openwisp-monitoring/tests/test_utils.lua b/openwrt-openwisp-monitoring/tests/test_utils.lua index a9e58e2..99a4174 100644 --- a/openwrt-openwisp-monitoring/tests/test_utils.lua +++ b/openwrt-openwisp-monitoring/tests/test_utils.lua @@ -7,53 +7,53 @@ local utils = require('monitoring_utils') TestUtils = {} function TestUtils.testSplitFunction() - -- When pattern is present - luaunit.assertEquals(utils.split("OpenWISP","n"), {"Ope", "WISP"}) - luaunit.assertEquals(utils.split("OpenWISP","WISP"), {"Open"}) + -- When pattern is present + luaunit.assertEquals(utils.split("OpenWISP","n"), {"Ope", "WISP"}) + luaunit.assertEquals(utils.split("OpenWISP","WISP"), {"Open"}) - -- When pattern is not available - luaunit.assertEquals(utils.split("OpenWISP","a"), {"OpenWISP"}) + -- When pattern is not available + luaunit.assertEquals(utils.split("OpenWISP","a"), {"OpenWISP"}) end function TestUtils.testHasValue() - -- When value is present - luaunit.assertEquals(utils.has_value({2,4,5},4), true) - luaunit.assertEquals(utils.has_value({1,2,3,7,9},9), true) + -- When value is present + luaunit.assertEquals(utils.has_value({2,4,5},4), true) + luaunit.assertEquals(utils.has_value({1,2,3,7,9},9), true) - -- When value is not present - luaunit.assertEquals(utils.has_value({2,4,5},3), false) - luaunit.assertEquals(utils.has_value({1,2,3,7,9},8), false) + -- When value is not present + luaunit.assertEquals(utils.has_value({2,4,5},3), false) + luaunit.assertEquals(utils.has_value({1,2,3,7,9},8), false) end function TestUtils.testStartsWith() - -- When string starts with the substring given - luaunit.assertEquals(utils.starts_with("OpenWISP", "Open"), true) - luaunit.assertEquals(utils.starts_with("NetJSON", "Net"), true) + -- When string starts with the substring given + luaunit.assertEquals(utils.starts_with("OpenWISP", "Open"), true) + luaunit.assertEquals(utils.starts_with("NetJSON", "Net"), true) - -- when string doesn't starts with the substring given - luaunit.assertEquals(utils.starts_with("OpenWISP", "Ov"), false) + -- when string doesn't starts with the substring given + luaunit.assertEquals(utils.starts_with("OpenWISP", "Ov"), false) end function TestUtils.testTableEmpty() - -- When table is empty - luaunit.assertEquals(utils.is_table_empty(nil), true) - luaunit.assertEquals(utils.is_table_empty({}), true) + -- When table is empty + luaunit.assertEquals(utils.is_table_empty(nil), true) + luaunit.assertEquals(utils.is_table_empty({}), true) - -- When table is not empty - luaunit.assertEquals(utils.is_table_empty({1,2,3,4}), false) - luaunit.assertEquals(utils.is_table_empty({"wireless", "wired", "system"}), false) + -- When table is not empty + luaunit.assertEquals(utils.is_table_empty({1,2,3,4}), false) + luaunit.assertEquals(utils.is_table_empty({"wireless", "wired", "system"}), false) end function TestUtils.testArrayConcat() - luaunit.assertEquals(utils.array_concat({4,5,6},{1,2,3}), {1, 2, 3, 4, 5, 6}) - luaunit.assertEquals(utils.array_concat({"wireless"},{"wired"}), {"wired", "wireless"}) - luaunit.assertEquals(utils.array_concat({"system", "network"},{"firewall"}), {"firewall", "system", "network"}) + luaunit.assertEquals(utils.array_concat({4,5,6},{1,2,3}), {1, 2, 3, 4, 5, 6}) + luaunit.assertEquals(utils.array_concat({"wireless"},{"wired"}), {"wired", "wireless"}) + luaunit.assertEquals(utils.array_concat({"system", "network"},{"firewall"}), {"firewall", "system", "network"}) end function TestUtils.testDictMerge() - luaunit.assertEquals(utils.dict_merge({['1']='OpenWISP'},{['3']='NetJSON'}), {["1"]="OpenWISP", ["3"]="NetJSON"}) - luaunit.assertEquals(utils.dict_merge({['1']='OpenWISP'},{['1']='NetJSON'}), {["1"]="OpenWISP"}) + luaunit.assertEquals(utils.dict_merge({['1']='OpenWISP'},{['3']='NetJSON'}), {["1"]="OpenWISP", ["3"]="NetJSON"}) + luaunit.assertEquals(utils.dict_merge({['1']='OpenWISP'},{['1']='NetJSON'}), {["1"]="OpenWISP"}) end os.exit(luaunit.LuaUnit.run())