Skip to content

Commit

Permalink
[tests] Increase coverage for dhcp and interface functions
Browse files Browse the repository at this point in the history
  • Loading branch information
devkapilbansal committed Jul 12, 2021
1 parent fdc452f commit 371110d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions openwrt-openwisp-monitoring/tests/test_dhcp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function TestDhcp.test_dhcp_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)
luaunit.assertEquals(dhcp_functions.parse_dhcp_lease_file('/tmp/no_dhcp.leases',{}), {})
end

function TestNetJSON.test_netjson_monitoring_dhcp()
Expand Down
14 changes: 13 additions & 1 deletion openwrt-openwisp-monitoring/tests/test_files/interface_data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ test_data.interface_data = {
address = "10.0.2.4",
mask = 24
} },
["ipv6-address"] = {},
["ipv6-address"] = { {
address = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
}},
["ipv6-prefix"] = {},
["ipv6-prefix-assignment"] = {},
l3_device = "eth1",
Expand All @@ -247,10 +249,20 @@ test_data.random_interface_address = {}

test_data.eth1_addresses = {
{address="10.0.2.4", family="ipv4", gateway="10.0.2.1", mask=24, proto="dhcp"},
{address="2001:0db8:85a3:0000:0000:8a2e:0370:7334", family="ipv6", gateway="10.0.2.1", proto="dhcp"},
{address="10.0.3.15", family="ipv4", mask=24, proto="dhcp"},
{address="fe80::a00:27ff:fe71:2291", family="ipv6", mask=64, proto="static"},
}

test_data.eth2_addresses = {
{address="192.168.0.144", family="ipv4", gateway="192.168.0.1", mask=24, proto="dhcp"},
{address="192.168.0.146", family="ipv4", mask=24, proto="dhcp"},
{address="fdf7:0c44:27ae:fe48:be0a", family="ipv6", mask=64, proto="static"}
}

test_data.br_mng_addresses = {
{address="192.168.56.2", family="ipv4", mask=24, proto="static"},
{address="fe81::a00:27ff:fed1:90b0", family="ipv6", mask=64, proto="dhcp"}
}

test_data.br_lan_interface = {
Expand Down
4 changes: 2 additions & 2 deletions openwrt-openwisp-monitoring/tests/test_files/nixio_data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ local nixio_data = { {
netmask = "ffff:ffff:ffff:ffff::",
prefix = 64
}, {
addr = "fe80::a00:27ff:fe48:be0a",
addr = "fdf7:0c44:27ae:fe48:be0a",
data = {},
family = "inet6",
flags = {
Expand All @@ -264,7 +264,7 @@ local nixio_data = { {
netmask = "ffff:ffff:ffff:ffff::",
prefix = 64
}, {
addr = "fe80::a00:27ff:fed1:90b0",
addr = "fe81::a00:27ff:fed1:90b0",
data = {},
family = "inet6",
flags = {
Expand Down
6 changes: 6 additions & 0 deletions openwrt-openwisp-monitoring/tests/test_interfaces.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ TestInterface = {
package.loaded.uci = env.uci
package.loaded.ubus = env.ubus
package.loaded.io = env.io
package.loaded.nixio = {
getifaddrs = function()
return require('test_files/nixio_data')
end
}
end,
tearDown = function()
end
Expand Down Expand Up @@ -38,6 +43,7 @@ function TestInterface.test_get_addresses()
local interface_functions = require('openwisp.interfaces')
luaunit.assertEquals(interface_functions.get_addresses('random'), interface_data.random_interface_address)
luaunit.assertEquals(interface_functions.get_addresses('eth1'), interface_data.eth1_addresses)
luaunit.assertEquals(interface_functions.get_addresses('eth2'), interface_data.eth2_addresses)
luaunit.assertEquals(interface_functions.get_addresses('br-mng'), interface_data.br_mng_addresses)
end

Expand Down

0 comments on commit 371110d

Please sign in to comment.