-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Added automated tests for lua code using mocks + test coverage
Closes #27
- Loading branch information
1 parent
b21f3bd
commit 91f319a
Showing
41 changed files
with
3,467 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
files["openwrt-openwisp-monitoring/tests"]={ | ||
ignore={"Test.*"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
#!/bin/sh | ||
set -e | ||
apt-get update | ||
# install lua | ||
#install cmake and git | ||
apt-get install -y cmake git | ||
#install lua | ||
apt-get install -y lua5.1 liblua5.1-0-dev luarocks | ||
#install json-c | ||
git clone https://github.com/json-c/json-c.git --depth=1 | ||
cd json-c && cmake . && make install && cd .. || { echo 'Installing json-c failed!' ; exit 1; } | ||
# install openwrt libubox and uci | ||
git clone https://git.openwrt.org/project/libubox.git --depth=1 | ||
cd libubox && cmake . && make install && cd .. || { echo 'Installing libubox failed!' ; exit 1; } | ||
git clone https://git.openwrt.org/project/uci.git --depth=1 | ||
cd uci && cmake . && make install && cd .. || { echo 'Installing uci failed!' ; exit 1; } | ||
#install nixio | ||
luarocks install https://raw.githubusercontent.com/Neopallium/nixio/master/nixio-scm-0.rockspec | ||
# update links to shared libraries | ||
ldconfig -v | ||
# install luaunit | ||
luarocks install luaunit | ||
# install luacheck | ||
luarocks install luacheck | ||
# install lua-cjson | ||
luarocks install lua-cjson | ||
#install luacov-coveralls | ||
luarocks install luacov-coveralls | ||
#clean | ||
rm -rf json-c libubox uci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
-- retrieve dhcp leases | ||
local utils = require('openwisp.monitoring_utils') | ||
|
||
local uci = require('uci') | ||
local uci_cursor = uci.cursor() | ||
package.path=package.path .. ";../files/lib/?.lua" | ||
|
||
local dhcp = {} | ||
-- retrieve dhcp leases | ||
local utils=require('openwisp.monitoring_utils') | ||
local uci=require('uci') | ||
local uci_cursor=uci.cursor() | ||
local io=require('io') | ||
local dhcp={} | ||
|
||
function dhcp.parse_dhcp_lease_file(path, leases) | ||
local f = io.open(path, 'r') | ||
if not f then | ||
return leases | ||
end | ||
for line in f:lines() do | ||
local expiry, mac, ip, name, id = line:match('(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)') | ||
table.insert(leases, { | ||
expiry = tonumber(expiry), | ||
mac = mac, | ||
ip = ip, | ||
client_name = name, | ||
client_id = id | ||
}) | ||
end | ||
|
||
local f=io.open(path, 'r') | ||
if not f then | ||
return leases | ||
end | ||
for line in f:lines() do | ||
local expiry, mac, ip, name, id=line:match('(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)') | ||
table.insert(leases, { | ||
expiry=tonumber(expiry), | ||
mac=mac, | ||
ip=ip, | ||
client_name=name, | ||
client_id=id | ||
}) | ||
end | ||
|
||
return leases | ||
end | ||
|
||
function dhcp.get_dhcp_leases() | ||
local dhcp_configs = uci_cursor:get_all('dhcp') | ||
local leases = {} | ||
local dhcp_configs=uci_cursor:get_all('dhcp') | ||
local leases={} | ||
|
||
if utils.is_table_empty(dhcp_configs) then | ||
return nil | ||
end | ||
if utils.is_table_empty(dhcp_configs) then | ||
return nil | ||
end | ||
|
||
for _, config in pairs(dhcp_configs) do | ||
if config and config['.type'] == 'dnsmasq' and config.leasefile then | ||
leases = dhcp.parse_dhcp_lease_file(config.leasefile, leases) | ||
end | ||
for _, config in pairs(dhcp_configs) do | ||
if config and config['.type']=='dnsmasq' and config.leasefile then | ||
leases=dhcp.parse_dhcp_lease_file(config.leasefile, leases) | ||
end | ||
return leases | ||
end | ||
return leases | ||
end | ||
|
||
return dhcp |
Oops, something went wrong.