Skip to content

Commit

Permalink
[refactor] Fix inconsistent indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
devkapilbansal committed Jun 17, 2021
1 parent 632102c commit 8f1e670
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 67 deletions.
46 changes: 23 additions & 23 deletions openwrt-openwisp-monitoring/tests/env1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 4 additions & 4 deletions openwrt-openwisp-monitoring/tests/test_dhcp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
14 changes: 7 additions & 7 deletions openwrt-openwisp-monitoring/tests/test_neighbors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
12 changes: 6 additions & 6 deletions openwrt-openwisp-monitoring/tests/test_resources.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
54 changes: 27 additions & 27 deletions openwrt-openwisp-monitoring/tests/test_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 8f1e670

Please sign in to comment.